Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4e189410
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看板
未验证
提交
4e189410
编写于
7月 16, 2022
作者:
L
Li Minghao
提交者:
GitHub
7月 16, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14990 from taosdata/feat/tsdb_snapshot
feat(tsdb/sync): tsdb snapshot/sync integration
上级
d3dca088
c978bd10
变更
19
展开全部
隐藏空白更改
内联
并排
Showing
19 changed file
with
1008 addition
and
486 deletion
+1008
-486
include/util/taoserror.h
include/util/taoserror.h
+0
-1
source/dnode/vnode/inc/vnode.h
source/dnode/vnode/inc/vnode.h
+1
-1
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+13
-13
source/dnode/vnode/src/inc/vnodeInt.h
source/dnode/vnode/src/inc/vnodeInt.h
+1
-0
source/dnode/vnode/src/meta/metaSnapshot.c
source/dnode/vnode/src/meta/metaSnapshot.c
+50
-39
source/dnode/vnode/src/tsdb/tsdbCache.c
source/dnode/vnode/src/tsdb/tsdbCache.c
+6
-8
source/dnode/vnode/src/tsdb/tsdbCommit.c
source/dnode/vnode/src/tsdb/tsdbCommit.c
+4
-13
source/dnode/vnode/src/tsdb/tsdbFS.c
source/dnode/vnode/src/tsdb/tsdbFS.c
+2
-2
source/dnode/vnode/src/tsdb/tsdbRead.c
source/dnode/vnode/src/tsdb/tsdbRead.c
+11
-12
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
+14
-14
source/dnode/vnode/src/tsdb/tsdbSnapshot.c
source/dnode/vnode/src/tsdb/tsdbSnapshot.c
+624
-224
source/dnode/vnode/src/tsdb/tsdbUtil.c
source/dnode/vnode/src/tsdb/tsdbUtil.c
+161
-22
source/dnode/vnode/src/vnd/vnodeSnapshot.c
source/dnode/vnode/src/vnd/vnodeSnapshot.c
+83
-52
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+1
-0
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+4
-1
source/libs/sync/src/syncAppendEntriesReply.c
source/libs/sync/src/syncAppendEntriesReply.c
+22
-1
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+11
-0
source/util/src/terror.c
source/util/src/terror.c
+0
-2
tests/script/tsim/sync/vnodesnapshot-test.sim
tests/script/tsim/sync/vnodesnapshot-test.sim
+0
-81
未找到文件。
include/util/taoserror.h
浏览文件 @
4e189410
...
...
@@ -332,7 +332,6 @@ int32_t* taosGetErrno();
#define TSDB_CODE_VND_INVALID_TABLE_ACTION TAOS_DEF_ERROR_CODE(0, 0x0519)
#define TSDB_CODE_VND_COL_ALREADY_EXISTS TAOS_DEF_ERROR_CODE(0, 0x051a)
#define TSDB_CODE_VND_TABLE_COL_NOT_EXISTS TAOS_DEF_ERROR_CODE(0, 0x051b)
#define TSDB_CODE_VND_READ_END TAOS_DEF_ERROR_CODE(0, 0x051c)
// tsdb
#define TSDB_CODE_TDB_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0600)
...
...
source/dnode/vnode/inc/vnode.h
浏览文件 @
4e189410
...
...
@@ -138,7 +138,7 @@ void *tsdbGetIdx(SMeta *pMeta);
void
*
tsdbGetIvtIdx
(
SMeta
*
pMeta
);
int32_t
tsdbLastRowReaderOpen
(
void
*
pVnode
,
int32_t
type
,
SArray
*
pTableIdList
,
int32_t
numOfCols
,
void
**
pReader
);
int32_t
tsdbRetrieveLastRow
(
void
*
pReader
,
SSDataBlock
*
pResBlock
,
const
int32_t
*
slotIds
,
SArray
*
pTableUids
);
int32_t
tsdbRetrieveLastRow
(
void
*
pReader
,
SSDataBlock
*
pResBlock
,
const
int32_t
*
slotIds
,
SArray
*
pTableUids
);
int32_t
tsdbLastrowReaderClose
(
void
*
pReader
);
int32_t
tsdbGetTableSchema
(
SVnode
*
pVnode
,
int64_t
uid
,
STSchema
**
pSchema
,
int64_t
*
suid
);
...
...
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
4e189410
...
...
@@ -24,12 +24,12 @@ extern "C" {
// tsdbDebug ================
// clang-format off
#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TSD
B
FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0)
#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TSD
B
ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0)
#define tsdbWarn(...) do { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TSD
B
WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0)
#define tsdbInfo(...) do { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TSD
B
", DEBUG_INFO, 255, __VA_ARGS__); }} while(0)
#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSD
B
", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0)
#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSD
B
", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0)
#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TSD FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0)
#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TSD ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0)
#define tsdbWarn(...) do { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TSD WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0)
#define tsdbInfo(...) do { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TSD ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0)
#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSD ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0)
#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSD ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0)
// clang-format on
typedef
struct
TSDBROW
TSDBROW
;
...
...
@@ -115,7 +115,6 @@ int32_t tGetBlock(uint8_t *p, void *ph);
int32_t
tBlockCmprFn
(
const
void
*
p1
,
const
void
*
p2
);
bool
tBlockHasSma
(
SBlock
*
pBlock
);
// SBlockIdx
void
tBlockIdxReset
(
SBlockIdx
*
pBlockIdx
);
int32_t
tPutBlockIdx
(
uint8_t
*
p
,
void
*
ph
);
int32_t
tGetBlockIdx
(
uint8_t
*
p
,
void
*
ph
);
int32_t
tCmprBlockIdx
(
void
const
*
lhs
,
void
const
*
rhs
);
...
...
@@ -126,6 +125,8 @@ void tColDataClear(void *ph);
int32_t
tColDataAppendValue
(
SColData
*
pColData
,
SColVal
*
pColVal
);
int32_t
tColDataGetValue
(
SColData
*
pColData
,
int32_t
iRow
,
SColVal
*
pColVal
);
int32_t
tColDataCopy
(
SColData
*
pColDataSrc
,
SColData
*
pColDataDest
);
int32_t
tPutColData
(
uint8_t
*
p
,
SColData
*
pColData
);
int32_t
tGetColData
(
uint8_t
*
p
,
SColData
*
pColData
);
// SBlockData
#define tBlockDataFirstRow(PBLOCKDATA) tsdbRowFromBlockData(PBLOCKDATA, 0)
#define tBlockDataLastRow(PBLOCKDATA) tsdbRowFromBlockData(PBLOCKDATA, (PBLOCKDATA)->nRow - 1)
...
...
@@ -134,14 +135,17 @@ int32_t tColDataCopy(SColData *pColDataSrc, SColData *pColDataDest);
int32_t
tBlockDataInit
(
SBlockData
*
pBlockData
);
void
tBlockDataReset
(
SBlockData
*
pBlockData
);
int32_t
tBlockDataSetSchema
(
SBlockData
*
pBlockData
,
STSchema
*
pTSchema
);
int32_t
tBlockDataCorrectSchema
(
SBlockData
*
pBlockData
,
SBlockData
*
pBlockDataFrom
);
void
tBlockDataClearData
(
SBlockData
*
pBlockData
);
void
tBlockDataClear
(
SBlockData
*
pBlockData
);
void
tBlockDataClear
(
SBlockData
*
pBlockData
,
int8_t
deepClear
);
int32_t
tBlockDataAddColData
(
SBlockData
*
pBlockData
,
int32_t
iColData
,
SColData
**
ppColData
);
int32_t
tBlockDataAppendRow
(
SBlockData
*
pBlockData
,
TSDBROW
*
pRow
,
STSchema
*
pTSchema
);
int32_t
tBlockDataMerge
(
SBlockData
*
pBlockData1
,
SBlockData
*
pBlockData2
,
SBlockData
*
pBlockData
);
int32_t
tBlockDataCopy
(
SBlockData
*
pBlockDataSrc
,
SBlockData
*
pBlockDataDest
);
SColData
*
tBlockDataGetColDataByIdx
(
SBlockData
*
pBlockData
,
int32_t
idx
);
void
tBlockDataGetColData
(
SBlockData
*
pBlockData
,
int16_t
cid
,
SColData
**
ppColData
);
int32_t
tPutBlockData
(
uint8_t
*
p
,
SBlockData
*
pBlockData
);
int32_t
tGetBlockData
(
uint8_t
*
p
,
SBlockData
*
pBlockData
);
// SDelIdx
int32_t
tPutDelIdx
(
uint8_t
*
p
,
void
*
ph
);
int32_t
tGetDelIdx
(
uint8_t
*
p
,
void
*
ph
);
...
...
@@ -202,7 +206,7 @@ int32_t tsdbFSStateUpsertDelFile(STsdbFSState *pState, SDelFile *pDelFile);
int32_t
tsdbFSStateUpsertDFileSet
(
STsdbFSState
*
pState
,
SDFileSet
*
pSet
);
void
tsdbFSStateDeleteDFileSet
(
STsdbFSState
*
pState
,
int32_t
fid
);
SDelFile
*
tsdbFSStateGetDelFile
(
STsdbFSState
*
pState
);
SDFileSet
*
tsdbFSStateGetDFileSet
(
STsdbFSState
*
pState
,
int32_t
fid
);
SDFileSet
*
tsdbFSStateGetDFileSet
(
STsdbFSState
*
pState
,
int32_t
fid
,
int32_t
flag
);
// tsdbReaderWriter.c ==============================================================================================
// SDataFWriter
int32_t
tsdbDataFWriterOpen
(
SDataFWriter
**
ppWriter
,
STsdb
*
pTsdb
,
SDFileSet
*
pSet
);
...
...
@@ -357,10 +361,6 @@ struct TSDBROW {
struct
SBlockIdx
{
int64_t
suid
;
int64_t
uid
;
TSKEY
minKey
;
TSKEY
maxKey
;
int64_t
minVersion
;
int64_t
maxVersion
;
int64_t
offset
;
int64_t
size
;
};
...
...
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
4e189410
...
...
@@ -309,6 +309,7 @@ void smaHandleRes(void* pVnode, int64_t smaId, const SArray* data);
struct
SSnapDataHdr
{
int8_t
type
;
int64_t
index
;
int64_t
size
;
uint8_t
data
[];
};
...
...
source/dnode/vnode/src/meta/metaSnapshot.c
浏览文件 @
4e189410
...
...
@@ -26,60 +26,72 @@ struct SMetaSnapReader {
int32_t
metaSnapReaderOpen
(
SMeta
*
pMeta
,
int64_t
sver
,
int64_t
ever
,
SMetaSnapReader
**
ppReader
)
{
int32_t
code
=
0
;
int32_t
c
=
0
;
SMetaSnapReader
*
p
MetaSnap
Reader
=
NULL
;
SMetaSnapReader
*
pReader
=
NULL
;
// alloc
p
MetaSnapReader
=
(
SMetaSnapReader
*
)
taosMemoryCalloc
(
1
,
sizeof
(
*
pMetaSna
pReader
));
if
(
p
MetaSnap
Reader
==
NULL
)
{
p
Reader
=
(
SMetaSnapReader
*
)
taosMemoryCalloc
(
1
,
sizeof
(
*
pReader
));
if
(
pReader
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
p
MetaSnap
Reader
->
pMeta
=
pMeta
;
p
MetaSnap
Reader
->
sver
=
sver
;
p
MetaSnap
Reader
->
ever
=
ever
;
pReader
->
pMeta
=
pMeta
;
pReader
->
sver
=
sver
;
pReader
->
ever
=
ever
;
// impl
code
=
tdbTbcOpen
(
pMeta
->
pTbDb
,
&
p
MetaSnap
Reader
->
pTbc
,
NULL
);
code
=
tdbTbcOpen
(
pMeta
->
pTbDb
,
&
pReader
->
pTbc
,
NULL
);
if
(
code
)
{
taosMemoryFree
(
pReader
);
goto
_err
;
}
code
=
tdbTbcMoveTo
(
p
MetaSnap
Reader
->
pTbc
,
&
(
STbDbKey
){.
version
=
sver
,
.
uid
=
INT64_MIN
},
sizeof
(
STbDbKey
),
&
c
);
code
=
tdbTbcMoveTo
(
pReader
->
pTbc
,
&
(
STbDbKey
){.
version
=
sver
,
.
uid
=
INT64_MIN
},
sizeof
(
STbDbKey
),
&
c
);
if
(
code
)
{
taosMemoryFree
(
pReader
);
goto
_err
;
}
*
ppReader
=
pMetaSnapReader
;
metaInfo
(
"vgId:%d vnode snapshot meta reader opened"
,
TD_VID
(
pMeta
->
pVnode
));
*
ppReader
=
pReader
;
return
code
;
_err:
metaError
(
"vgId:%d
meta snap
reader open failed since %s"
,
TD_VID
(
pMeta
->
pVnode
),
tstrerror
(
code
));
metaError
(
"vgId:%d
vnode snapshot meta
reader open failed since %s"
,
TD_VID
(
pMeta
->
pVnode
),
tstrerror
(
code
));
*
ppReader
=
NULL
;
return
code
;
}
int32_t
metaSnapReaderClose
(
SMetaSnapReader
**
ppReader
)
{
int32_t
code
=
0
;
tdbTbcClose
((
*
ppReader
)
->
pTbc
);
taosMemoryFree
(
*
ppReader
);
*
ppReader
=
NULL
;
return
0
;
return
code
;
}
int32_t
metaSnapRead
(
SMetaSnapReader
*
pReader
,
uint8_t
**
ppData
)
{
int32_t
code
=
0
;
const
void
*
pKey
=
NULL
;
const
void
*
pData
=
NULL
;
int32_t
nKey
=
0
;
int32_t
nData
=
0
;
int32_t
code
=
0
;
STbDbKey
key
;
*
ppData
=
NULL
;
for
(;;)
{
code
=
tdbTbcGet
(
pReader
->
pTbc
,
&
pKey
,
&
nKey
,
&
pData
,
&
nData
);
if
(
code
||
((
STbDbKey
*
)
pData
)
->
version
>
pReader
->
ever
)
{
code
=
TSDB_CODE_VND_READ_END
;
if
(
tdbTbcGet
(
pReader
->
pTbc
,
&
pKey
,
&
nKey
,
&
pData
,
&
nData
))
{
goto
_exit
;
}
if
(((
STbDbKey
*
)
pData
)
->
version
<
pReader
->
sver
)
{
key
=
((
STbDbKey
*
)
pKey
)[
0
];
if
(
key
.
version
>
pReader
->
ever
)
{
goto
_exit
;
}
if
(
key
.
version
<
pReader
->
sver
)
{
tdbTbcMoveToNext
(
pReader
->
pTbc
);
continue
;
}
...
...
@@ -88,17 +100,28 @@ int32_t metaSnapRead(SMetaSnapReader* pReader, uint8_t** ppData) {
break
;
}
// copy the data
if
(
tRealloc
(
ppData
,
sizeof
(
SSnapDataHdr
)
+
nData
)
<
0
)
{
ASSERT
(
pData
&&
nData
);
*
ppData
=
taosMemoryMalloc
(
sizeof
(
SSnapDataHdr
)
+
nData
);
if
(
*
ppData
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
return
code
;
goto
_err
;
}
((
SSnapDataHdr
*
)(
*
ppData
))
->
type
=
0
;
// TODO: use macro
((
SSnapDataHdr
*
)(
*
ppData
))
->
size
=
nData
;
memcpy
(((
SSnapDataHdr
*
)(
*
ppData
))
->
data
,
pData
,
nData
);
SSnapDataHdr
*
pHdr
=
(
SSnapDataHdr
*
)(
*
ppData
);
pHdr
->
type
=
0
;
// TODO: use macro
pHdr
->
size
=
nData
;
memcpy
(
pHdr
->
data
,
pData
,
nData
);
metaInfo
(
"vgId:%d vnode snapshot meta read data, version:%"
PRId64
" uid:%"
PRId64
" nData:%d"
,
TD_VID
(
pReader
->
pMeta
->
pVnode
),
key
.
version
,
key
.
uid
,
nData
);
_exit:
return
code
;
_err:
metaError
(
"vgId:%d vnode snapshot meta read data failed since %s"
,
TD_VID
(
pReader
->
pMeta
->
pVnode
),
tstrerror
(
code
));
return
code
;
}
// SMetaSnapWriter ========================================
...
...
@@ -108,18 +131,6 @@ struct SMetaSnapWriter {
int64_t
ever
;
};
static
int32_t
metaSnapRollback
(
SMetaSnapWriter
*
pWriter
)
{
int32_t
code
=
0
;
// TODO
return
code
;
}
static
int32_t
metaSnapCommit
(
SMetaSnapWriter
*
pWriter
)
{
int32_t
code
=
0
;
// TODO
return
code
;
}
int32_t
metaSnapWriterOpen
(
SMeta
*
pMeta
,
int64_t
sver
,
int64_t
ever
,
SMetaSnapWriter
**
ppWriter
)
{
int32_t
code
=
0
;
SMetaSnapWriter
*
pWriter
;
...
...
@@ -148,10 +159,9 @@ int32_t metaSnapWriterClose(SMetaSnapWriter** ppWriter, int8_t rollback) {
SMetaSnapWriter
*
pWriter
=
*
ppWriter
;
if
(
rollback
)
{
code
=
metaSnapRollback
(
pWriter
);
if
(
code
)
goto
_err
;
ASSERT
(
0
);
}
else
{
code
=
meta
SnapCommit
(
pWriter
);
code
=
meta
Commit
(
pWriter
->
pMeta
);
if
(
code
)
goto
_err
;
}
taosMemoryFree
(
pWriter
);
...
...
@@ -170,15 +180,16 @@ int32_t metaSnapWrite(SMetaSnapWriter* pWriter, uint8_t* pData, uint32_t nData)
SMetaEntry
metaEntry
=
{
0
};
SDecoder
*
pDecoder
=
&
(
SDecoder
){
0
};
tDecoderInit
(
pDecoder
,
pData
,
nData
);
tDecoderInit
(
pDecoder
,
pData
+
sizeof
(
SSnapDataHdr
),
nData
-
sizeof
(
SSnapDataHdr
)
);
metaDecodeEntry
(
pDecoder
,
&
metaEntry
);
code
=
metaHandleEntry
(
pMeta
,
&
metaEntry
);
if
(
code
)
goto
_err
;
tDecoderClear
(
pDecoder
);
return
code
;
_err:
metaError
(
"vgId:%d
meta snapshot
write failed since %s"
,
TD_VID
(
pMeta
->
pVnode
),
tstrerror
(
code
));
metaError
(
"vgId:%d
vnode snapshot meta
write failed since %s"
,
TD_VID
(
pMeta
->
pVnode
),
tstrerror
(
code
));
return
code
;
}
\ No newline at end of file
source/dnode/vnode/src/tsdb/tsdbCache.c
浏览文件 @
4e189410
...
...
@@ -476,9 +476,9 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow) {
if
(
--
state
->
iFileSet
>=
0
)
{
pFileSet
=
(
SDFileSet
*
)
taosArrayGet
(
state
->
aDFileSet
,
state
->
iFileSet
);
}
else
{
// tBlockDataClear(&state->blockData);
// tBlockDataClear(&state->blockData
, 1
);
if
(
state
->
pBlockData
)
{
tBlockDataClear
(
state
->
pBlockData
);
tBlockDataClear
(
state
->
pBlockData
,
1
);
state
->
pBlockData
=
NULL
;
}
...
...
@@ -500,9 +500,7 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow) {
if
(
code
)
goto
_err
;
/* if (state->pBlockIdx) { */
/* tBlockIdxReset(state->blockIdx); */
/* } */
/* tBlockIdxReset(state->blockIdx); */
/* code = tMapDataSearch(&state->blockIdxMap, state->pBlockIdxExp, tGetBlockIdx, tCmprBlockIdx,
* &state->blockIdx);
*/
...
...
@@ -582,8 +580,8 @@ _err:
state
->
aBlockIdx
=
NULL
;
}
if
(
state
->
pBlockData
)
{
// tBlockDataClear(&state->blockData);
tBlockDataClear
(
state
->
pBlockData
);
// tBlockDataClear(&state->blockData
, 1
);
tBlockDataClear
(
state
->
pBlockData
,
1
);
state
->
pBlockData
=
NULL
;
}
...
...
@@ -609,8 +607,8 @@ int32_t clearNextRowFromFS(void *iter) {
state
->
aBlockIdx
=
NULL
;
}
if
(
state
->
pBlockData
)
{
// tBlockDataClear(&state->blockData);
tBlockDataClear
(
state
->
pBlockData
);
// tBlockDataClear(&state->blockData
, 1
);
tBlockDataClear
(
state
->
pBlockData
,
1
);
state
->
pBlockData
=
NULL
;
}
...
...
source/dnode/vnode/src/tsdb/tsdbCommit.c
浏览文件 @
4e189410
...
...
@@ -263,7 +263,7 @@ static int32_t tsdbCommitFileDataStart(SCommitter *pCommitter) {
taosArrayClear
(
pCommitter
->
aBlockIdx
);
tMapDataReset
(
&
pCommitter
->
oBlockMap
);
tBlockDataReset
(
&
pCommitter
->
oBlockData
);
pRSet
=
tsdbFSStateGetDFileSet
(
pTsdb
->
fs
->
nState
,
pCommitter
->
commitFid
);
pRSet
=
tsdbFSStateGetDFileSet
(
pTsdb
->
fs
->
nState
,
pCommitter
->
commitFid
,
TD_EQ
);
if
(
pRSet
)
{
code
=
tsdbDataFReaderOpen
(
&
pCommitter
->
pReader
,
pTsdb
,
pRSet
);
if
(
code
)
goto
_err
;
...
...
@@ -284,16 +284,7 @@ static int32_t tsdbCommitFileDataStart(SCommitter *pCommitter) {
.
fLast
=
{.
commitID
=
pCommitter
->
commitID
,
.
size
=
0
},
.
fSma
=
pRSet
->
fSma
};
}
else
{
STfs
*
pTfs
=
pTsdb
->
pVnode
->
pTfs
;
SDiskID
did
=
{.
level
=
0
,
.
id
=
0
};
// TODO: alloc a new disk
// tfsAllocDisk(pTfs, 0, &did);
// create the directory
tfsMkdirRecurAt
(
pTfs
,
pTsdb
->
path
,
did
);
wSet
=
(
SDFileSet
){.
diskId
=
did
,
wSet
=
(
SDFileSet
){.
diskId
=
(
SDiskID
){.
level
=
0
,
.
id
=
0
},
.
fid
=
pCommitter
->
commitFid
,
.
fHead
=
{.
commitID
=
pCommitter
->
commitID
,
.
offset
=
0
,
.
size
=
0
},
.
fData
=
{.
commitID
=
pCommitter
->
commitID
,
.
size
=
0
},
...
...
@@ -1001,10 +992,10 @@ _exit:
static
void
tsdbCommitDataEnd
(
SCommitter
*
pCommitter
)
{
taosArrayDestroy
(
pCommitter
->
aBlockIdx
);
tMapDataClear
(
&
pCommitter
->
oBlockMap
);
tBlockDataClear
(
&
pCommitter
->
oBlockData
);
tBlockDataClear
(
&
pCommitter
->
oBlockData
,
1
);
taosArrayDestroy
(
pCommitter
->
aBlockIdxN
);
tMapDataClear
(
&
pCommitter
->
nBlockMap
);
tBlockDataClear
(
&
pCommitter
->
nBlockData
);
tBlockDataClear
(
&
pCommitter
->
nBlockData
,
1
);
tTSchemaDestroy
(
pCommitter
->
skmTable
.
pTSchema
);
tTSchemaDestroy
(
pCommitter
->
skmRow
.
pTSchema
);
}
...
...
source/dnode/vnode/src/tsdb/tsdbFS.c
浏览文件 @
4e189410
...
...
@@ -698,6 +698,6 @@ void tsdbFSStateDeleteDFileSet(STsdbFSState *pState, int32_t fid) {
SDelFile
*
tsdbFSStateGetDelFile
(
STsdbFSState
*
pState
)
{
return
pState
->
pDelFile
;
}
SDFileSet
*
tsdbFSStateGetDFileSet
(
STsdbFSState
*
pState
,
int32_t
fid
)
{
return
(
SDFileSet
*
)
taosArraySearch
(
pState
->
aDFileSet
,
&
(
SDFileSet
){.
fid
=
fid
},
tDFileSetCmprFn
,
TD_EQ
);
SDFileSet
*
tsdbFSStateGetDFileSet
(
STsdbFSState
*
pState
,
int32_t
fid
,
int32_t
flag
)
{
return
(
SDFileSet
*
)
taosArraySearch
(
pState
->
aDFileSet
,
&
(
SDFileSet
){.
fid
=
fid
},
tDFileSetCmprFn
,
flag
);
}
source/dnode/vnode/src/tsdb/tsdbRead.c
浏览文件 @
4e189410
...
...
@@ -63,10 +63,10 @@ typedef struct SBlockLoadSuppInfo {
}
SBlockLoadSuppInfo
;
typedef
struct
SFilesetIter
{
int32_t
numOfFiles
;
// number of total files
int32_t
index
;
// current accessed index in the list
SArray
*
pFileList
;
// data file list
int32_t
order
;
int32_t
numOfFiles
;
// number of total files
int32_t
index
;
// current accessed index in the list
SArray
*
pFileList
;
// data file list
int32_t
order
;
}
SFilesetIter
;
typedef
struct
SFileDataBlockInfo
{
...
...
@@ -830,8 +830,8 @@ static int32_t doLoadFileBlockData(STsdbReader* pReader, SDataBlockIter* pBlockI
SBlockLoadSuppInfo
*
pSupInfo
=
&
pReader
->
suppInfo
;
SFileBlockDumpInfo
*
pDumpInfo
=
&
pReader
->
status
.
fBlockDumpInfo
;
int32_t
code
=
tsdbReadColData
(
pReader
->
pFileReader
,
&
pBlockScanInfo
->
blockIdx
,
pBlock
,
pSupInfo
->
colIds
,
numOfCols
,
pBlockData
,
NULL
,
NULL
);
int32_t
code
=
tsdbReadColData
(
pReader
->
pFileReader
,
&
pBlockScanInfo
->
blockIdx
,
pBlock
,
pSupInfo
->
colIds
,
numOfCols
,
pBlockData
,
NULL
,
NULL
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
}
...
...
@@ -1991,7 +1991,7 @@ static TSDBKEY getCurrentKeyInBuf(SDataBlockIter* pBlockIter, STsdbReader* pRead
static
int32_t
moveToNextFile
(
STsdbReader
*
pReader
,
int32_t
*
numOfBlocks
)
{
SReaderStatus
*
pStatus
=
&
pReader
->
status
;
SArray
*
pIndexList
=
taosArrayInit
(
4
,
sizeof
(
SBlockIdx
));
SArray
*
pIndexList
=
taosArrayInit
(
4
,
sizeof
(
SBlockIdx
));
while
(
1
)
{
bool
hasNext
=
filesetIteratorNext
(
&
pStatus
->
fileIter
,
pReader
);
...
...
@@ -3006,14 +3006,14 @@ SArray* tsdbRetrieveDataBlock(STsdbReader* pReader, SArray* pIdList) {
code
=
doLoadFileBlockData
(
pReader
,
&
pStatus
->
blockIter
,
pBlockScanInfo
,
&
pStatus
->
fileBlockData
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
tBlockDataClear
(
&
pStatus
->
fileBlockData
);
tBlockDataClear
(
&
pStatus
->
fileBlockData
,
1
);
terrno
=
code
;
return
NULL
;
}
copyBlockDataToSDataBlock
(
pReader
,
pBlockScanInfo
);
tBlockDataClear
(
&
pStatus
->
fileBlockData
);
tBlockDataClear
(
&
pStatus
->
fileBlockData
,
1
);
return
pReader
->
pResBlock
->
pDataBlock
;
}
...
...
@@ -3132,8 +3132,8 @@ int32_t tsdbGetFileBlocksDistInfo(STsdbReader* pReader, STableBlockDistInfo* pTa
hasNext
=
(
pBlockIter
->
numOfBlocks
>
0
);
}
// tsdbDebug("%p %d blocks found in file for %d table(s), fid:%d, %s", pReader, numOfBlocks, numOfTables,
// pReader->pFileGroup->fid, pReader->idStr);
// tsdbDebug("%p %d blocks found in file for %d table(s), fid:%d, %s", pReader, numOfBlocks, numOfTables,
// pReader->pFileGroup->fid, pReader->idStr);
}
return
code
;
...
...
@@ -3204,4 +3204,3 @@ int32_t tsdbGetTableSchema(SVnode* pVnode, int64_t uid, STSchema** pSchema, int6
return
TSDB_CODE_SUCCESS
;
}
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
浏览文件 @
4e189410
...
...
@@ -979,21 +979,21 @@ int32_t tsdbReadColData(SDataFReader *pReader, SBlockIdx *pBlockIdx, SBlock *pBl
code
=
tBlockDataCopy
(
pBlockData
,
pBlockData2
);
if
(
code
)
{
tBlockDataClear
(
pBlockData1
);
tBlockDataClear
(
pBlockData2
);
tBlockDataClear
(
pBlockData1
,
1
);
tBlockDataClear
(
pBlockData2
,
1
);
goto
_err
;
}
code
=
tBlockDataMerge
(
pBlockData1
,
pBlockData2
,
pBlockData
);
if
(
code
)
{
tBlockDataClear
(
pBlockData1
);
tBlockDataClear
(
pBlockData2
);
tBlockDataClear
(
pBlockData1
,
1
);
tBlockDataClear
(
pBlockData2
,
1
);
goto
_err
;
}
}
tBlockDataClear
(
pBlockData1
);
tBlockDataClear
(
pBlockData2
);
tBlockDataClear
(
pBlockData1
,
1
);
tBlockDataClear
(
pBlockData2
,
1
);
}
tFree
(
pBuf1
);
...
...
@@ -1115,29 +1115,29 @@ int32_t tsdbReadBlockData(SDataFReader *pReader, SBlockIdx *pBlockIdx, SBlock *p
for
(
iSubBlock
=
1
;
iSubBlock
<
pBlock
->
nSubBlock
;
iSubBlock
++
)
{
code
=
tsdbReadSubBlockData
(
pReader
,
pBlockIdx
,
pBlock
,
iSubBlock
,
pBlockData1
,
ppBuf1
,
ppBuf2
);
if
(
code
)
{
tBlockDataClear
(
pBlockData1
);
tBlockDataClear
(
pBlockData2
);
tBlockDataClear
(
pBlockData1
,
1
);
tBlockDataClear
(
pBlockData2
,
1
);
goto
_err
;
}
code
=
tBlockDataCopy
(
pBlockData
,
pBlockData2
);
if
(
code
)
{
tBlockDataClear
(
pBlockData1
);
tBlockDataClear
(
pBlockData2
);
tBlockDataClear
(
pBlockData1
,
1
);
tBlockDataClear
(
pBlockData2
,
1
);
goto
_err
;
}
// merge two block data
code
=
tBlockDataMerge
(
pBlockData1
,
pBlockData2
,
pBlockData
);
if
(
code
)
{
tBlockDataClear
(
pBlockData1
);
tBlockDataClear
(
pBlockData2
);
tBlockDataClear
(
pBlockData1
,
1
);
tBlockDataClear
(
pBlockData2
,
1
);
goto
_err
;
}
}
tBlockDataClear
(
pBlockData1
);
tBlockDataClear
(
pBlockData2
);
tBlockDataClear
(
pBlockData1
,
1
);
tBlockDataClear
(
pBlockData2
,
1
);
}
ASSERT
(
pBlock
->
nRow
==
pBlockData
->
nRow
);
...
...
source/dnode/vnode/src/tsdb/tsdbSnapshot.c
浏览文件 @
4e189410
此差异已折叠。
点击以展开。
source/dnode/vnode/src/tsdb/tsdbUtil.c
浏览文件 @
4e189410
...
...
@@ -36,15 +36,15 @@ int32_t tMapDataPutItem(SMapData *pMapData, void *pItem, int32_t (*tPutItemFn)(u
// alloc
code
=
tRealloc
((
uint8_t
**
)
&
pMapData
->
aOffset
,
sizeof
(
int32_t
)
*
pMapData
->
nItem
);
if
(
code
)
goto
_e
rr
;
if
(
code
)
goto
_e
xit
;
code
=
tRealloc
(
&
pMapData
->
pData
,
pMapData
->
nData
);
if
(
code
)
goto
_e
rr
;
if
(
code
)
goto
_e
xit
;
// put
pMapData
->
aOffset
[
nItem
]
=
offset
;
tPutItemFn
(
pMapData
->
pData
+
offset
,
pItem
);
_e
rr
:
_e
xit
:
return
code
;
}
...
...
@@ -189,25 +189,12 @@ static FORCE_INLINE int32_t tGetTSDBKEY(uint8_t *p, TSDBKEY *pKey) {
}
// SBlockIdx ======================================================
void
tBlockIdxReset
(
SBlockIdx
*
pBlockIdx
)
{
pBlockIdx
->
minKey
=
TSKEY_MAX
;
pBlockIdx
->
maxKey
=
TSKEY_MIN
;
pBlockIdx
->
minVersion
=
VERSION_MAX
;
pBlockIdx
->
maxVersion
=
VERSION_MIN
;
pBlockIdx
->
offset
=
-
1
;
pBlockIdx
->
size
=
-
1
;
}
int32_t
tPutBlockIdx
(
uint8_t
*
p
,
void
*
ph
)
{
int32_t
n
=
0
;
SBlockIdx
*
pBlockIdx
=
(
SBlockIdx
*
)
ph
;
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pBlockIdx
->
suid
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pBlockIdx
->
uid
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pBlockIdx
->
minKey
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pBlockIdx
->
maxKey
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pBlockIdx
->
minVersion
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pBlockIdx
->
maxVersion
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pBlockIdx
->
offset
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pBlockIdx
->
size
);
...
...
@@ -220,10 +207,6 @@ int32_t tGetBlockIdx(uint8_t *p, void *ph) {
n
+=
tGetI64
(
p
+
n
,
&
pBlockIdx
->
suid
);
n
+=
tGetI64
(
p
+
n
,
&
pBlockIdx
->
uid
);
n
+=
tGetI64
(
p
+
n
,
&
pBlockIdx
->
minKey
);
n
+=
tGetI64
(
p
+
n
,
&
pBlockIdx
->
maxKey
);
n
+=
tGetI64v
(
p
+
n
,
&
pBlockIdx
->
minVersion
);
n
+=
tGetI64v
(
p
+
n
,
&
pBlockIdx
->
maxVersion
);
n
+=
tGetI64v
(
p
+
n
,
&
pBlockIdx
->
offset
);
n
+=
tGetI64v
(
p
+
n
,
&
pBlockIdx
->
size
);
...
...
@@ -921,6 +904,76 @@ _exit:
return
code
;
}
int32_t
tPutColData
(
uint8_t
*
p
,
SColData
*
pColData
)
{
int32_t
n
=
0
;
n
+=
tPutI16v
(
p
?
p
+
n
:
p
,
pColData
->
cid
);
n
+=
tPutI8
(
p
?
p
+
n
:
p
,
pColData
->
type
);
n
+=
tPutI8
(
p
?
p
+
n
:
p
,
pColData
->
smaOn
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
pColData
->
nVal
);
n
+=
tPutU8
(
p
?
p
+
n
:
p
,
pColData
->
flag
);
if
(
pColData
->
flag
==
HAS_NONE
||
pColData
->
flag
==
HAS_NULL
)
goto
_exit
;
if
(
pColData
->
flag
!=
HAS_VALUE
)
{
// bitmap
int32_t
size
=
BIT2_SIZE
(
pColData
->
nVal
);
if
(
p
)
{
memcpy
(
p
+
n
,
pColData
->
pBitMap
,
size
);
}
n
+=
size
;
}
if
(
IS_VAR_DATA_TYPE
(
pColData
->
type
))
{
// offset
int32_t
size
=
sizeof
(
int32_t
)
*
pColData
->
nVal
;
if
(
p
)
{
memcpy
(
p
+
n
,
pColData
->
aOffset
,
size
);
}
n
+=
size
;
}
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
pColData
->
nData
);
if
(
p
)
{
memcpy
(
p
+
n
,
pColData
->
pData
,
pColData
->
nData
);
}
n
+=
pColData
->
nData
;
_exit:
return
n
;
}
int32_t
tGetColData
(
uint8_t
*
p
,
SColData
*
pColData
)
{
int32_t
n
=
0
;
n
+=
tGetI16v
(
p
+
n
,
&
pColData
->
cid
);
n
+=
tGetI8
(
p
+
n
,
&
pColData
->
type
);
n
+=
tGetI8
(
p
+
n
,
&
pColData
->
smaOn
);
n
+=
tGetI32v
(
p
+
n
,
&
pColData
->
nVal
);
n
+=
tGetU8
(
p
+
n
,
&
pColData
->
flag
);
if
(
pColData
->
flag
==
HAS_NONE
||
pColData
->
flag
==
HAS_NULL
)
goto
_exit
;
if
(
pColData
->
flag
!=
HAS_VALUE
)
{
// bitmap
int32_t
size
=
BIT2_SIZE
(
pColData
->
nVal
);
pColData
->
pBitMap
=
p
+
n
;
n
+=
size
;
}
if
(
IS_VAR_DATA_TYPE
(
pColData
->
type
))
{
// offset
int32_t
size
=
sizeof
(
int32_t
)
*
pColData
->
nVal
;
pColData
->
aOffset
=
(
int32_t
*
)(
p
+
n
);
n
+=
size
;
}
n
+=
tGetI32v
(
p
+
n
,
&
pColData
->
nData
);
pColData
->
pData
=
p
+
n
;
n
+=
pColData
->
nData
;
_exit:
return
n
;
}
static
FORCE_INLINE
int32_t
tColDataCmprFn
(
const
void
*
p1
,
const
void
*
p2
)
{
SColData
*
pColData1
=
(
SColData
*
)
p1
;
SColData
*
pColData2
=
(
SColData
*
)
p2
;
...
...
@@ -962,11 +1015,11 @@ void tBlockDataReset(SBlockData *pBlockData) {
taosArrayClear
(
pBlockData
->
aIdx
);
}
void
tBlockDataClear
(
SBlockData
*
pBlockData
)
{
void
tBlockDataClear
(
SBlockData
*
pBlockData
,
int8_t
deepClear
)
{
tFree
((
uint8_t
*
)
pBlockData
->
aVersion
);
tFree
((
uint8_t
*
)
pBlockData
->
aTSKEY
);
taosArrayDestroy
(
pBlockData
->
aIdx
);
taosArrayDestroyEx
(
pBlockData
->
aColData
,
tColDataClear
);
taosArrayDestroyEx
(
pBlockData
->
aColData
,
deepClear
?
tColDataClear
:
NULL
);
}
int32_t
tBlockDataSetSchema
(
SBlockData
*
pBlockData
,
STSchema
*
pTSchema
)
{
...
...
@@ -1079,6 +1132,46 @@ _err:
return
code
;
}
int32_t
tBlockDataCorrectSchema
(
SBlockData
*
pBlockData
,
SBlockData
*
pBlockDataFrom
)
{
int32_t
code
=
0
;
int32_t
iColData
=
0
;
for
(
int32_t
iColDataFrom
=
0
;
iColDataFrom
<
taosArrayGetSize
(
pBlockDataFrom
->
aIdx
);
iColDataFrom
++
)
{
SColData
*
pColDataFrom
=
tBlockDataGetColDataByIdx
(
pBlockDataFrom
,
iColDataFrom
);
while
(
true
)
{
SColData
*
pColData
;
if
(
iColData
<
taosArrayGetSize
(
pBlockData
->
aIdx
))
{
pColData
=
tBlockDataGetColDataByIdx
(
pBlockData
,
iColData
);
}
else
{
pColData
=
NULL
;
}
if
(
pColData
==
NULL
||
pColData
->
cid
>
pColDataFrom
->
cid
)
{
code
=
tBlockDataAddColData
(
pBlockData
,
iColData
,
&
pColData
);
if
(
code
)
goto
_exit
;
tColDataInit
(
pColData
,
pColDataFrom
->
cid
,
pColDataFrom
->
type
,
pColDataFrom
->
smaOn
);
for
(
int32_t
iRow
=
0
;
iRow
<
pBlockData
->
nRow
;
iRow
++
)
{
code
=
tColDataAppendValue
(
pColData
,
&
COL_VAL_NONE
(
pColData
->
cid
,
pColData
->
type
));
if
(
code
)
goto
_exit
;
}
iColData
++
;
break
;
}
else
if
(
pColData
->
cid
==
pColDataFrom
->
cid
)
{
iColData
++
;
break
;
}
else
{
iColData
++
;
}
}
}
_exit:
return
code
;
}
int32_t
tBlockDataMerge
(
SBlockData
*
pBlockData1
,
SBlockData
*
pBlockData2
,
SBlockData
*
pBlockData
)
{
int32_t
code
=
0
;
...
...
@@ -1239,6 +1332,52 @@ void tBlockDataGetColData(SBlockData *pBlockData, int16_t cid, SColData **ppColD
*
ppColData
=
NULL
;
}
int32_t
tPutBlockData
(
uint8_t
*
p
,
SBlockData
*
pBlockData
)
{
int32_t
n
=
0
;
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
pBlockData
->
nRow
);
if
(
p
)
{
memcpy
(
p
+
n
,
pBlockData
->
aVersion
,
sizeof
(
int64_t
)
*
pBlockData
->
nRow
);
}
n
=
n
+
sizeof
(
int64_t
)
*
pBlockData
->
nRow
;
if
(
p
)
{
memcpy
(
p
+
n
,
pBlockData
->
aTSKEY
,
sizeof
(
TSKEY
)
*
pBlockData
->
nRow
);
}
n
=
n
+
sizeof
(
TSKEY
)
*
pBlockData
->
nRow
;
int32_t
nCol
=
taosArrayGetSize
(
pBlockData
->
aIdx
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
nCol
);
for
(
int32_t
iCol
=
0
;
iCol
<
nCol
;
iCol
++
)
{
SColData
*
pColData
=
tBlockDataGetColDataByIdx
(
pBlockData
,
iCol
);
n
+=
tPutColData
(
p
?
p
+
n
:
p
,
pColData
);
}
return
n
;
}
int32_t
tGetBlockData
(
uint8_t
*
p
,
SBlockData
*
pBlockData
)
{
int32_t
n
=
0
;
tBlockDataReset
(
pBlockData
);
n
+=
tGetI32v
(
p
+
n
,
&
pBlockData
->
nRow
);
pBlockData
->
aVersion
=
(
int64_t
*
)(
p
+
n
);
n
=
n
+
sizeof
(
int64_t
)
*
pBlockData
->
nRow
;
pBlockData
->
aTSKEY
=
(
TSKEY
*
)(
p
+
n
);
n
=
n
+
sizeof
(
TSKEY
)
*
pBlockData
->
nRow
;
int32_t
nCol
;
n
+=
tGetI32v
(
p
+
n
,
&
nCol
);
for
(
int32_t
iCol
=
0
;
iCol
<
nCol
;
iCol
++
)
{
SColData
*
pColData
;
if
(
tBlockDataAddColData
(
pBlockData
,
iCol
,
&
pColData
))
return
-
1
;
n
+=
tGetColData
(
p
+
n
,
pColData
);
}
return
n
;
}
// ALGORITHM ==============================
void
tsdbCalcColDataSMA
(
SColData
*
pColData
,
SColumnDataAgg
*
pColAgg
)
{
SColVal
colVal
;
...
...
source/dnode/vnode/src/vnd/vnodeSnapshot.c
浏览文件 @
4e189410
...
...
@@ -20,13 +20,13 @@ struct SVSnapReader {
SVnode
*
pVnode
;
int64_t
sver
;
int64_t
ever
;
int64_t
index
;
// meta
int8_t
metaDone
;
SMetaSnapReader
*
pMetaReader
;
// tsdb
int8_t
tsdbDone
;
STsdbSnapReader
*
pTsdbReader
;
uint8_t
*
pData
;
};
int32_t
vnodeSnapReaderOpen
(
SVnode
*
pVnode
,
int64_t
sver
,
int64_t
ever
,
SVSnapReader
**
ppReader
)
{
...
...
@@ -42,12 +42,7 @@ int32_t vnodeSnapReaderOpen(SVnode *pVnode, int64_t sver, int64_t ever, SVSnapRe
pReader
->
sver
=
sver
;
pReader
->
ever
=
ever
;
code
=
metaSnapReaderOpen
(
pVnode
->
pMeta
,
sver
,
ever
,
&
pReader
->
pMetaReader
);
if
(
code
)
goto
_err
;
code
=
tsdbSnapReaderOpen
(
pVnode
->
pTsdb
,
sver
,
ever
,
&
pReader
->
pTsdbReader
);
if
(
code
)
goto
_err
;
vInfo
(
"vgId:%d vnode snapshot reader opened, sver:%"
PRId64
" ever:%"
PRId64
,
TD_VID
(
pVnode
),
sver
,
ever
);
*
ppReader
=
pReader
;
return
code
;
...
...
@@ -60,54 +55,85 @@ _err:
int32_t
vnodeSnapReaderClose
(
SVSnapReader
*
pReader
)
{
int32_t
code
=
0
;
tFree
(
pReader
->
pData
);
if
(
pReader
->
pTsdbReader
)
tsdbSnapReaderClose
(
&
pReader
->
pTsdbReader
);
if
(
pReader
->
pMetaReader
)
metaSnapReaderClose
(
&
pReader
->
pMetaReader
);
taosMemoryFree
(
pReader
);
if
(
pReader
->
pTsdbReader
)
{
tsdbSnapReaderClose
(
&
pReader
->
pTsdbReader
);
}
if
(
pReader
->
pMetaReader
)
{
metaSnapReaderClose
(
&
pReader
->
pMetaReader
);
}
vInfo
(
"vgId:%d vnode snapshot reader closed"
,
TD_VID
(
pReader
->
pVnode
));
taosMemoryFree
(
pReader
);
return
code
;
}
int32_t
vnodeSnapRead
(
SVSnapReader
*
pReader
,
uint8_t
**
ppData
,
uint32_t
*
nData
)
{
int32_t
code
=
0
;
// META ==============
if
(
!
pReader
->
metaDone
)
{
code
=
metaSnapRead
(
pReader
->
pMetaReader
,
&
pReader
->
pData
);
// open reader if not
if
(
pReader
->
pMetaReader
==
NULL
)
{
code
=
metaSnapReaderOpen
(
pReader
->
pVnode
->
pMeta
,
pReader
->
sver
,
pReader
->
ever
,
&
pReader
->
pMetaReader
);
if
(
code
)
goto
_err
;
}
code
=
metaSnapRead
(
pReader
->
pMetaReader
,
ppData
);
if
(
code
)
{
if
(
code
==
TSDB_CODE_VND_READ_END
)
{
pReader
->
metaDone
=
1
;
goto
_err
;
}
else
{
if
(
*
ppData
)
{
goto
_exit
;
}
else
{
goto
_err
;
pReader
->
metaDone
=
1
;
code
=
metaSnapReaderClose
(
&
pReader
->
pMetaReader
);
if
(
code
)
goto
_err
;
}
}
else
{
*
ppData
=
pReader
->
pData
;
*
nData
=
sizeof
(
SSnapDataHdr
)
+
((
SSnapDataHdr
*
)
pReader
->
pData
)
->
size
;
goto
_exit
;
}
}
// TSDB ==============
if
(
!
pReader
->
tsdbDone
)
{
code
=
tsdbSnapRead
(
pReader
->
pTsdbReader
,
&
pReader
->
pData
);
// open if not
if
(
pReader
->
pTsdbReader
==
NULL
)
{
code
=
tsdbSnapReaderOpen
(
pReader
->
pVnode
->
pTsdb
,
pReader
->
sver
,
pReader
->
ever
,
&
pReader
->
pTsdbReader
);
if
(
code
)
goto
_err
;
}
code
=
tsdbSnapRead
(
pReader
->
pTsdbReader
,
ppData
);
if
(
code
)
{
if
(
code
==
TSDB_CODE_VND_READ_END
)
{
pReader
->
tsdbDone
=
1
;
goto
_err
;
}
else
{
if
(
*
ppData
)
{
goto
_exit
;
}
else
{
goto
_err
;
pReader
->
tsdbDone
=
1
;
code
=
tsdbSnapReaderClose
(
&
pReader
->
pTsdbReader
);
if
(
code
)
goto
_err
;
}
}
else
{
*
ppData
=
pReader
->
pData
;
*
nData
=
sizeof
(
SSnapDataHdr
)
+
((
SSnapDataHdr
*
)
pReader
->
pData
)
->
size
;
goto
_exit
;
}
}
code
=
TSDB_CODE_VND_READ_END
;
*
ppData
=
NULL
;
*
nData
=
0
;
_exit:
if
(
*
ppData
)
{
SSnapDataHdr
*
pHdr
=
(
SSnapDataHdr
*
)(
*
ppData
);
pReader
->
index
++
;
*
nData
=
sizeof
(
SSnapDataHdr
)
+
pHdr
->
size
;
pHdr
->
index
=
pReader
->
index
;
vInfo
(
"vgId:%d vnode snapshot read data,index:%"
PRId64
" type:%d nData:%d "
,
TD_VID
(
pReader
->
pVnode
),
pReader
->
index
,
pHdr
->
type
,
*
nData
);
}
else
{
vInfo
(
"vgId:%d vnode snapshot read data end, index:%"
PRId64
,
TD_VID
(
pReader
->
pVnode
),
pReader
->
index
);
}
return
code
;
_err:
vError
(
"vgId:% snapshot read failed since %s"
,
TD_VID
(
pReader
->
pVnode
),
tstrerror
(
code
));
vError
(
"vgId:%
vnode
snapshot read failed since %s"
,
TD_VID
(
pReader
->
pVnode
),
tstrerror
(
code
));
return
code
;
}
...
...
@@ -116,24 +142,13 @@ struct SVSnapWriter {
SVnode
*
pVnode
;
int64_t
sver
;
int64_t
ever
;
int64_t
index
;
// meta
SMetaSnapWriter
*
pMetaSnapWriter
;
// tsdb
STsdbSnapWriter
*
pTsdbSnapWriter
;
};
static
int32_t
vnodeSnapRollback
(
SVSnapWriter
*
pWriter
)
{
int32_t
code
=
0
;
// TODO
return
code
;
}
static
int32_t
vnodeSnapCommit
(
SVSnapWriter
*
pWriter
)
{
int32_t
code
=
0
;
// TODO
return
code
;
}
int32_t
vnodeSnapWriterOpen
(
SVnode
*
pVnode
,
int64_t
sver
,
int64_t
ever
,
SVSnapWriter
**
ppWriter
)
{
int32_t
code
=
0
;
SVSnapWriter
*
pWriter
=
NULL
;
...
...
@@ -148,62 +163,78 @@ int32_t vnodeSnapWriterOpen(SVnode *pVnode, int64_t sver, int64_t ever, SVSnapWr
pWriter
->
sver
=
sver
;
pWriter
->
ever
=
ever
;
vInfo
(
"vgId:%d vnode snapshot writer opened"
,
TD_VID
(
pVnode
));
*
ppWriter
=
pWriter
;
return
code
;
_err:
vError
(
"vgId:%d vnode snapshot writer open failed since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
code
));
*
ppWriter
=
NULL
;
return
code
;
}
int32_t
vnodeSnapWriterClose
(
SVSnapWriter
*
pWriter
,
int8_t
rollback
)
{
int32_t
code
=
0
;
if
(
rollback
)
{
code
=
vnodeSnapRollback
(
pWriter
);
if
(
pWriter
->
pMetaSnapWriter
)
{
code
=
metaSnapWriterClose
(
&
pWriter
->
pMetaSnapWriter
,
rollback
);
if
(
code
)
goto
_err
;
}
else
{
code
=
vnodeSnapCommit
(
pWriter
);
}
if
(
pWriter
->
pTsdbSnapWriter
)
{
code
=
tsdbSnapWriterClose
(
&
pWriter
->
pTsdbSnapWriter
,
rollback
);
if
(
code
)
goto
_err
;
}
_exit:
vInfo
(
"vgId:%d vnode snapshot writer closed, rollback:%d"
,
TD_VID
(
pWriter
->
pVnode
),
rollback
);
taosMemoryFree
(
pWriter
);
return
code
;
_err:
vError
(
"vgId:%d vnode snapsho
w
writer close failed since %s"
,
TD_VID
(
pWriter
->
pVnode
),
tstrerror
(
code
));
vError
(
"vgId:%d vnode snapsho
t
writer close failed since %s"
,
TD_VID
(
pWriter
->
pVnode
),
tstrerror
(
code
));
return
code
;
}
int32_t
vnodeSnapWrite
(
SVSnapWriter
*
pWriter
,
uint8_t
*
pData
,
uint32_t
nData
)
{
int32_t
code
=
0
;
SSnapDataHdr
*
p
SnapData
Hdr
=
(
SSnapDataHdr
*
)
pData
;
SSnapDataHdr
*
pHdr
=
(
SSnapDataHdr
*
)
pData
;
SVnode
*
pVnode
=
pWriter
->
pVnode
;
ASSERT
(
pSnapDataHdr
->
size
+
sizeof
(
SSnapDataHdr
)
==
nData
);
ASSERT
(
pHdr
->
size
+
sizeof
(
SSnapDataHdr
)
==
nData
);
ASSERT
(
pHdr
->
index
==
pWriter
->
index
+
1
);
pWriter
->
index
=
pHdr
->
index
;
if
(
pSnapDataHdr
->
type
==
0
)
{
vInfo
(
"vgId:%d vnode snapshot write data, index:%"
PRId64
" type:%d nData:%d"
,
TD_VID
(
pVnode
),
pHdr
->
index
,
pHdr
->
type
,
nData
);
if
(
pHdr
->
type
==
0
)
{
// meta
if
(
pWriter
->
pMetaSnapWriter
==
NULL
)
{
code
=
metaSnapWriterOpen
(
pVnode
->
pMeta
,
pWriter
->
sver
,
pWriter
->
ever
,
&
pWriter
->
pMetaSnapWriter
);
if
(
code
)
goto
_err
;
}
code
=
metaSnapWrite
(
pWriter
->
pMetaSnapWriter
,
pData
+
sizeof
(
SSnapDataHdr
),
nData
-
sizeof
(
SSnapDataHdr
)
);
code
=
metaSnapWrite
(
pWriter
->
pMetaSnapWriter
,
pData
,
nData
);
if
(
code
)
goto
_err
;
}
else
{
// tsdb
if
(
pWriter
->
pTsdbSnapWriter
==
NULL
)
{
code
=
tsdbSnapWriterOpen
(
pVnode
->
pTsdb
,
pWriter
->
sver
,
pWriter
->
ever
,
&
pWriter
->
pTsdbSnapWriter
);
if
(
code
)
goto
_err
;
}
code
=
tsdbSnapWrite
(
pWriter
->
pTsdbSnapWriter
,
pData
+
sizeof
(
SSnapDataHdr
),
nData
-
sizeof
(
SSnapDataHdr
)
);
code
=
tsdbSnapWrite
(
pWriter
->
pTsdbSnapWriter
,
pData
,
nData
);
if
(
code
)
goto
_err
;
}
_exit:
return
code
;
_err:
vError
(
"vgId:%d vnode snapshot write failed since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
code
));
vError
(
"vgId:%d vnode snapshot write failed since %s, index:%"
PRId64
" type:%d nData:%d"
,
TD_VID
(
pVnode
),
tstrerror
(
code
),
pHdr
->
index
,
pHdr
->
type
,
nData
);
return
code
;
}
\ No newline at end of file
source/libs/sync/inc/syncInt.h
浏览文件 @
4e189410
...
...
@@ -223,6 +223,7 @@ void syncNodeVoteForSelf(SSyncNode* pSyncNode);
// snapshot --------------
bool
syncNodeHasSnapshot
(
SSyncNode
*
pSyncNode
);
void
syncNodeMaybeUpdateCommitBySnapshot
(
SSyncNode
*
pSyncNode
);
SyncIndex
syncNodeGetLastIndex
(
SSyncNode
*
pSyncNode
);
SyncTerm
syncNodeGetLastTerm
(
SSyncNode
*
pSyncNode
);
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
4e189410
...
...
@@ -711,6 +711,9 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
syncNodeEventLog
(
ths
,
logBuf
);
}
while
(
0
);
// maybe update commit index by snapshot
syncNodeMaybeUpdateCommitBySnapshot
(
ths
);
// prepare response msg
SyncAppendEntriesReply
*
pReply
=
syncAppendEntriesReplyBuild
(
ths
->
vgId
);
pReply
->
srcId
=
ths
->
myRaftId
;
...
...
@@ -718,7 +721,7 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
pReply
->
term
=
ths
->
pRaftStore
->
currentTerm
;
pReply
->
privateTerm
=
ths
->
pNewNodeReceiver
->
privateTerm
;
pReply
->
success
=
false
;
pReply
->
matchIndex
=
SYNC_INDEX_INVALID
;
pReply
->
matchIndex
=
ths
->
commitIndex
;
// msg event log
do
{
...
...
source/libs/sync/src/syncAppendEntriesReply.c
浏览文件 @
4e189410
...
...
@@ -147,6 +147,15 @@ static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, Sync
int32_t
syncNodeOnAppendEntriesReplySnapshot2Cb
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
)
{
int32_t
ret
=
0
;
// print log
do
{
char
logBuf
[
256
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"recv sync-append-entries-reply, term:%lu, match:%ld, success:%d"
,
pMsg
->
term
,
pMsg
->
matchIndex
,
pMsg
->
success
);
syncNodeEventLog
(
ths
,
logBuf
);
}
while
(
0
);
// if already drop replica, do not process
if
(
!
syncNodeInRaftGroup
(
ths
,
&
(
pMsg
->
srcId
))
&&
!
ths
->
pRaftCfg
->
isStandBy
)
{
syncNodeEventLog
(
ths
,
"recv sync-append-entries-reply, maybe replica already dropped"
);
...
...
@@ -238,7 +247,14 @@ int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntrie
SSnapshot
oldSnapshot
;
ths
->
pFsm
->
FpGetSnapshotInfo
(
ths
->
pFsm
,
&
oldSnapshot
);
SyncTerm
newSnapshotTerm
=
oldSnapshot
.
lastApplyTerm
;
syncNodeStartSnapshotOnce
(
ths
,
SYNC_INDEX_BEGIN
,
nextIndex
,
newSnapshotTerm
,
pMsg
);
SyncIndex
endIndex
;
if
(
ths
->
pLogStore
->
syncLogExist
(
ths
->
pLogStore
,
nextIndex
+
1
))
{
endIndex
=
nextIndex
;
}
else
{
endIndex
=
oldSnapshot
.
lastApplyIndex
;
}
syncNodeStartSnapshotOnce
(
ths
,
pMsg
->
matchIndex
+
1
,
endIndex
,
newSnapshotTerm
,
pMsg
);
// get sender
SSyncSnapshotSender
*
pSender
=
syncNodeGetSnapshotSender
(
ths
,
&
(
pMsg
->
srcId
));
...
...
@@ -256,6 +272,11 @@ int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntrie
}
syncIndexMgrSetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
),
nextIndex
);
SyncIndex
oldMatchIndex
=
syncIndexMgrGetIndex
(
ths
->
pMatchIndex
,
&
(
pMsg
->
srcId
));
if
(
pMsg
->
matchIndex
>
oldMatchIndex
)
{
syncIndexMgrSetIndex
(
ths
->
pMatchIndex
,
&
(
pMsg
->
srcId
),
pMsg
->
matchIndex
);
}
// event log, update next-index
do
{
char
host
[
64
];
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
4e189410
...
...
@@ -1083,6 +1083,17 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
return
pSyncNode
;
}
void
syncNodeMaybeUpdateCommitBySnapshot
(
SSyncNode
*
pSyncNode
)
{
if
(
pSyncNode
->
pFsm
!=
NULL
&&
pSyncNode
->
pFsm
->
FpGetSnapshotInfo
!=
NULL
)
{
SSnapshot
snapshot
;
int32_t
code
=
pSyncNode
->
pFsm
->
FpGetSnapshotInfo
(
pSyncNode
->
pFsm
,
&
snapshot
);
ASSERT
(
code
==
0
);
if
(
snapshot
.
lastApplyIndex
>
pSyncNode
->
commitIndex
)
{
pSyncNode
->
commitIndex
=
snapshot
.
lastApplyIndex
;
}
}
}
void
syncNodeStart
(
SSyncNode
*
pSyncNode
)
{
// start raft
if
(
pSyncNode
->
replicaNum
==
1
)
{
...
...
source/util/src/terror.c
浏览文件 @
4e189410
...
...
@@ -336,8 +336,6 @@ TAOS_DEFINE_ERROR(TSDB_CODE_VND_TABLE_NOT_EXIST, "Table does not exists
TAOS_DEFINE_ERROR
(
TSDB_CODE_VND_INVALID_TABLE_ACTION
,
"Invalid table action"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_VND_COL_ALREADY_EXISTS
,
"Table column already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_VND_TABLE_COL_NOT_EXISTS
,
"Table column not exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_VND_READ_END
,
"Read end"
)
// tsdb
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_INVALID_TABLE_ID
,
"Invalid table ID"
)
...
...
tests/script/tsim/sync/vnodesnapshot-test.sim
浏览文件 @
4e189410
...
...
@@ -170,84 +170,3 @@ if $rows != 100 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
system sh/exec.sh -n dnode4 -s stop -x SIGINT
########################################################
########################################################
print ===> start dnode1 dnode3 dnode4
system sh/exec.sh -n dnode1 -s start
#system sh/exec.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start
system sh/exec.sh -n dnode4 -s start
sleep 7000
print =============== query data
sql connect
sql use db
sql select * from ct1
print rows: $rows
print $data00 $data01 $data02
if $rows != 100 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
#system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
system sh/exec.sh -n dnode4 -s stop -x SIGINT
########################################################
########################################################
print ===> start dnode1 dnode2 dnode4
system sh/exec.sh -n dnode1 -s start
system sh/exec.sh -n dnode2 -s start
#system sh/exec.sh -n dnode3 -s start
system sh/exec.sh -n dnode4 -s start
sleep 3000
print =============== query data
sql select * from ct1
print rows: $rows
print $data00 $data01 $data02
if $rows != 100 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT
#system sh/exec.sh -n dnode3 -s stop -x SIGINT
system sh/exec.sh -n dnode4 -s stop -x SIGINT
########################################################
########################################################
print ===> start dnode1 dnode2 dnode3
system sh/exec.sh -n dnode1 -s start
system sh/exec.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start
#system sh/exec.sh -n dnode4 -s start
sleep 3000
print =============== query data
sql select * from ct1
print rows: $rows
print $data00 $data01 $data02
if $rows != 100 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
#system sh/exec.sh -n dnode4 -s stop -x SIGINT
########################################################
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录