Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
1e94822a
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
1e94822a
编写于
11月 26, 2020
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-1926
上级
810023ca
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
56 addition
and
88 deletion
+56
-88
src/inc/tsync.h
src/inc/tsync.h
+4
-0
src/sync/inc/syncInt.h
src/sync/inc/syncInt.h
+2
-0
src/sync/src/syncMain.c
src/sync/src/syncMain.c
+1
-0
src/sync/src/syncRestore.c
src/sync/src/syncRestore.c
+4
-4
src/sync/src/syncRetrieve.c
src/sync/src/syncRetrieve.c
+20
-82
src/vnode/inc/vnodeInt.h
src/vnode/inc/vnodeInt.h
+1
-0
src/vnode/src/vnodeMain.c
src/vnode/src/vnodeMain.c
+23
-1
src/vnode/src/vnodeWrite.c
src/vnode/src/vnodeWrite.c
+1
-1
未找到文件。
src/inc/tsync.h
浏览文件 @
1e94822a
...
...
@@ -85,6 +85,9 @@ typedef void (*FNotifyFlowCtrl)(int32_t vgId, int32_t level);
// when data file is synced successfully, notity app
typedef
int32_t
(
*
FNotifyFileSynced
)(
int32_t
vgId
,
uint64_t
fversion
);
// get file version
typedef
int32_t
(
*
FGetFileVersion
)(
int32_t
vgId
,
uint64_t
*
fver
);
typedef
struct
{
int32_t
vgId
;
// vgroup ID
uint64_t
version
;
// initial version
...
...
@@ -97,6 +100,7 @@ typedef struct {
FNotifyRole
notifyRole
;
FNotifyFlowCtrl
notifyFlowCtrl
;
FNotifyFileSynced
notifyFileSynced
;
FGetFileVersion
getFileVersion
;
}
SSyncInfo
;
typedef
void
*
tsync_h
;
...
...
src/sync/inc/syncInt.h
浏览文件 @
1e94822a
...
...
@@ -139,6 +139,7 @@ typedef struct SsyncPeer {
char
id
[
TSDB_EP_LEN
+
32
];
// peer vgId + end point
uint64_t
version
;
uint64_t
sversion
;
// track the peer version in retrieve process
uint64_t
lastVer
;
// track the file version while retrieve
int32_t
syncFd
;
int32_t
peerFd
;
// forward FD
int32_t
numOfRetrieves
;
// number of retrieves tried
...
...
@@ -172,6 +173,7 @@ typedef struct SSyncNode {
FNotifyRole
notifyRole
;
FNotifyFlowCtrl
notifyFlowCtrl
;
FNotifyFileSynced
notifyFileSynced
;
FGetFileVersion
getFileVersion
;
pthread_mutex_t
mutex
;
}
SSyncNode
;
...
...
src/sync/src/syncMain.c
浏览文件 @
1e94822a
...
...
@@ -196,6 +196,7 @@ int64_t syncStart(const SSyncInfo *pInfo) {
pNode
->
confirmForward
=
pInfo
->
confirmForward
;
pNode
->
notifyFlowCtrl
=
pInfo
->
notifyFlowCtrl
;
pNode
->
notifyFileSynced
=
pInfo
->
notifyFileSynced
;
pNode
->
getFileVersion
=
pInfo
->
getFileVersion
;
pNode
->
selfIndex
=
-
1
;
pNode
->
vgId
=
pInfo
->
vgId
;
...
...
src/sync/src/syncRestore.c
浏览文件 @
1e94822a
...
...
@@ -52,12 +52,12 @@ static void syncRemoveExtraFile(SSyncPeer *pPeer, int32_t sindex, int32_t eindex
static
int32_t
syncRestoreFile
(
SSyncPeer
*
pPeer
,
uint64_t
*
fversion
)
{
SSyncNode
*
pNode
=
pPeer
->
pSyncNode
;
SFileInfo
minfo
;
memset
(
&
minfo
,
0
,
sizeof
(
minfo
));
/* = {0}; */
// master file info
SFileInfo
sinfo
;
memset
(
&
sinfo
,
0
,
sizeof
(
sinfo
));
/* = {0}; */
// slave file info
SFileAck
fileAck
;
SFileInfo
minfo
=
{
0
};
SFileInfo
sinfo
=
{
0
};
SFileAck
fileAck
=
{
0
};
int32_t
code
=
-
1
;
char
name
[
TSDB_FILENAME_LEN
*
2
]
=
{
0
};
uint32_t
pindex
=
0
;
// index in last restore
uint32_t
pindex
=
0
;
// index in last restore
bool
fileChanged
=
false
;
*
fversion
=
0
;
...
...
src/sync/src/syncRetrieve.c
浏览文件 @
1e94822a
...
...
@@ -25,85 +25,32 @@
#include "tsync.h"
#include "syncInt.h"
static
int32_t
syncAddIntoWatchList
(
SSyncPeer
*
pPeer
,
char
*
name
)
{
sDebug
(
"%s, start to monitor:%s"
,
pPeer
->
id
,
name
);
if
(
pPeer
->
notifyFd
<=
0
)
{
pPeer
->
watchNum
=
0
;
pPeer
->
notifyFd
=
inotify_init1
(
IN_NONBLOCK
);
if
(
pPeer
->
notifyFd
<
0
)
{
sError
(
"%s, failed to init inotify since %s"
,
pPeer
->
id
,
strerror
(
errno
));
return
-
1
;
}
if
(
pPeer
->
watchFd
==
NULL
)
pPeer
->
watchFd
=
malloc
(
sizeof
(
int32_t
)
*
tsMaxWatchFiles
);
if
(
pPeer
->
watchFd
==
NULL
)
{
sError
(
"%s, failed to allocate watchFd"
,
pPeer
->
id
);
return
-
1
;
}
memset
(
pPeer
->
watchFd
,
-
1
,
sizeof
(
int32_t
)
*
tsMaxWatchFiles
);
}
int32_t
*
wd
=
pPeer
->
watchFd
+
pPeer
->
watchNum
;
if
(
*
wd
>=
0
)
{
if
(
inotify_rm_watch
(
pPeer
->
notifyFd
,
*
wd
)
<
0
)
{
sError
(
"%s, failed to remove wd:%d since %s"
,
pPeer
->
id
,
*
wd
,
strerror
(
errno
));
return
-
1
;
}
static
int32_t
syncAreFilesModified
(
SSyncNode
*
pNode
,
SSyncPeer
*
pPeer
)
{
if
(
pNode
->
getFileVersion
==
NULL
)
return
0
;
uint64_t
fver
=
0
;
int32_t
code
=
(
*
pNode
->
getFileVersion
)(
pNode
->
vgId
,
&
fver
);
if
(
code
!=
0
)
{
sInfo
(
"%s, file are modified while retrieve, lastver:%"
PRIu64
,
pPeer
->
id
,
pPeer
->
lastVer
);
return
code
;
}
*
wd
=
inotify_add_watch
(
pPeer
->
notifyFd
,
name
,
IN_MODIFY
|
IN_DELETE
);
if
(
*
wd
==
-
1
)
{
sError
(
"%s, failed to add %s since %s"
,
pPeer
->
id
,
name
,
strerror
(
errno
));
if
(
fver
!=
pPeer
->
lastVer
)
{
sInfo
(
"%s, file are modified while retrieve, fver:%"
PRIu64
" lastver:%"
PRIu64
,
pPeer
->
id
,
fver
,
pPeer
->
lastVer
);
return
-
1
;
}
else
{
sDebug
(
"%s, monitor %s, wd:%d watchNum:%d"
,
pPeer
->
id
,
name
,
*
wd
,
pPeer
->
watchNum
);
}
pPeer
->
watchNum
=
(
pPeer
->
watchNum
+
1
)
%
tsMaxWatchFiles
;
return
0
;
}
static
int32_t
syncAreFilesModified
(
SSyncPeer
*
pPeer
)
{
if
(
pPeer
->
notifyFd
<=
0
)
return
0
;
char
buf
[
2048
];
int32_t
len
=
read
(
pPeer
->
notifyFd
,
buf
,
sizeof
(
buf
));
if
(
len
<
0
&&
errno
!=
EAGAIN
)
{
sError
(
"%s, failed to read notify FD since %s"
,
pPeer
->
id
,
strerror
(
errno
));
return
-
1
;
}
int32_t
code
=
0
;
if
(
len
>
0
)
{
const
struct
inotify_event
*
event
;
char
*
ptr
;
for
(
ptr
=
buf
;
ptr
<
buf
+
len
;
ptr
+=
sizeof
(
struct
inotify_event
)
+
event
->
len
)
{
event
=
(
const
struct
inotify_event
*
)
ptr
;
if
((
event
->
mask
&
IN_MODIFY
)
||
(
event
->
mask
&
IN_DELETE
))
{
sDebug
(
"%s, processed file is changed"
,
pPeer
->
id
);
pPeer
->
fileChanged
=
1
;
code
=
1
;
break
;
}
}
}
return
code
;
}
static
int32_t
syncRetrieveFile
(
SSyncPeer
*
pPeer
)
{
SSyncNode
*
pNode
=
pPeer
->
pSyncNode
;
SFileInfo
fileInfo
;
SFileAck
fileAck
;
SFileInfo
fileInfo
=
{
0
}
;
SFileAck
fileAck
=
{
0
}
;
int32_t
code
=
-
1
;
char
name
[
TSDB_FILENAME_LEN
*
2
]
=
{
0
};
memset
(
&
fileInfo
,
0
,
sizeof
(
fileInfo
));
memset
(
&
fileAck
,
0
,
sizeof
(
fileAck
));
if
(
pNode
->
getFileVersion
)
(
*
pNode
->
getFileVersion
)(
pNode
->
vgId
,
&
pPeer
->
lastVer
);
while
(
1
)
{
// retrieve file info
...
...
@@ -136,15 +83,6 @@ static int32_t syncRetrieveFile(SSyncPeer *pPeer) {
// set the peer sync version
pPeer
->
sversion
=
fileInfo
.
fversion
;
// get the full path to file
snprintf
(
name
,
sizeof
(
name
),
"%s/%s"
,
pNode
->
path
,
fileInfo
.
name
);
// add the file into watch list
if
(
syncAddIntoWatchList
(
pPeer
,
name
)
<
0
)
{
sError
(
"%s, failed to watch file:%s while retrieve file since %s"
,
pPeer
->
id
,
fileInfo
.
name
,
strerror
(
errno
));
break
;
}
// if sync is not required, continue
if
(
fileAck
.
sync
==
0
)
{
fileInfo
.
index
++
;
...
...
@@ -152,6 +90,9 @@ static int32_t syncRetrieveFile(SSyncPeer *pPeer) {
continue
;
}
// get the full path to file
snprintf
(
name
,
sizeof
(
name
),
"%s/%s"
,
pNode
->
path
,
fileInfo
.
name
);
// send the file to peer
int32_t
sfd
=
open
(
name
,
O_RDONLY
);
if
(
sfd
<
0
)
{
...
...
@@ -170,10 +111,7 @@ static int32_t syncRetrieveFile(SSyncPeer *pPeer) {
fileInfo
.
index
++
;
// check if processed files are modified
if
(
syncAreFilesModified
(
pPeer
)
!=
0
)
{
sInfo
(
"%s, file:%s are modified while retrieve file since %s"
,
pPeer
->
id
,
fileInfo
.
name
,
strerror
(
errno
));
break
;
}
if
(
syncAreFilesModified
(
pNode
,
pPeer
)
!=
0
)
break
;
}
if
(
code
<
0
)
{
...
...
@@ -308,9 +246,9 @@ static int32_t syncRetrieveLastWal(SSyncPeer *pPeer, char *name, uint64_t fversi
static
int32_t
syncProcessLastWal
(
SSyncPeer
*
pPeer
,
char
*
wname
,
int64_t
index
)
{
SSyncNode
*
pNode
=
pPeer
->
pSyncNode
;
int32_t
code
=
-
1
;
char
fname
[
TSDB_FILENAME_LEN
*
2
];
// full path to wal file
char
fname
[
TSDB_FILENAME_LEN
*
2
]
=
{
0
}
;
// full path to wal file
if
(
syncAreFilesModified
(
pPeer
)
!=
0
)
return
-
1
;
if
(
syncAreFilesModified
(
p
Node
,
p
Peer
)
!=
0
)
return
-
1
;
while
(
1
)
{
int32_t
once
=
0
;
// last WAL has once ever been processed
...
...
@@ -431,7 +369,7 @@ static int32_t syncRetrieveWal(SSyncPeer *pPeer) {
index
++
;
if
(
syncAreFilesModified
(
pPeer
)
!=
0
)
break
;
if
(
syncAreFilesModified
(
p
Node
,
p
Peer
)
!=
0
)
break
;
}
if
(
code
==
0
)
{
...
...
src/vnode/inc/vnodeInt.h
浏览文件 @
1e94822a
...
...
@@ -44,6 +44,7 @@ typedef struct {
int8_t
role
;
int8_t
accessState
;
int8_t
isFull
;
int8_t
isCommiting
;
uint64_t
version
;
// current version
uint64_t
fversion
;
// version on saved data file
void
*
wqueue
;
...
...
src/vnode/src/vnodeMain.c
浏览文件 @
1e94822a
...
...
@@ -38,6 +38,7 @@ static void vnodeCtrlFlow(int32_t vgId, int32_t level);
static
int32_t
vnodeNotifyFileSynced
(
int32_t
vgId
,
uint64_t
fversion
);
static
void
vnodeConfirmForard
(
int32_t
vgId
,
void
*
wparam
,
int32_t
code
);
static
int32_t
vnodeWriteToCache
(
int32_t
vgId
,
void
*
wparam
,
int32_t
qtype
,
void
*
rparam
);
static
int32_t
vnodeGetFileVersion
(
int32_t
vgId
,
uint64_t
*
fver
);
#ifndef _SYNC
int64_t
syncStart
(
const
SSyncInfo
*
info
)
{
return
NULL
;
}
...
...
@@ -352,6 +353,7 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
syncInfo
.
notifyRole
=
vnodeNotifyRole
;
syncInfo
.
notifyFlowCtrl
=
vnodeCtrlFlow
;
syncInfo
.
notifyFileSynced
=
vnodeNotifyFileSynced
;
syncInfo
.
getFileVersion
=
vnodeGetFileVersion
;
pVnode
->
sync
=
syncStart
(
&
syncInfo
);
#ifndef _SYNC
...
...
@@ -597,18 +599,19 @@ static void vnodeCleanUp(SVnodeObj *pVnode) {
vnodeRelease
(
pVnode
);
}
// TODO: this is a simple implement
static
int32_t
vnodeProcessTsdbStatus
(
void
*
arg
,
int32_t
status
,
int32_t
eno
)
{
SVnodeObj
*
pVnode
=
arg
;
if
(
eno
!=
TSDB_CODE_SUCCESS
)
{
vError
(
"vgId:%d, failed to commit since %s, fver:%"
PRIu64
" vver:%"
PRIu64
,
pVnode
->
vgId
,
tstrerror
(
eno
),
pVnode
->
fversion
,
pVnode
->
version
);
pVnode
->
isCommiting
=
0
;
pVnode
->
isFull
=
1
;
return
0
;
}
if
(
status
==
TSDB_STATUS_COMMIT_START
)
{
pVnode
->
isCommiting
=
1
;
pVnode
->
fversion
=
pVnode
->
version
;
vDebug
(
"vgId:%d, start commit, fver:%"
PRIu64
" vver:%"
PRIu64
,
pVnode
->
vgId
,
pVnode
->
fversion
,
pVnode
->
version
);
if
(
pVnode
->
status
!=
TAOS_VN_STATUS_INIT
)
{
...
...
@@ -619,6 +622,7 @@ static int32_t vnodeProcessTsdbStatus(void *arg, int32_t status, int32_t eno) {
if
(
status
==
TSDB_STATUS_COMMIT_OVER
)
{
vDebug
(
"vgId:%d, commit over, fver:%"
PRIu64
" vver:%"
PRIu64
,
pVnode
->
vgId
,
pVnode
->
fversion
,
pVnode
->
version
);
pVnode
->
isCommiting
=
0
;
pVnode
->
isFull
=
0
;
if
(
pVnode
->
status
!=
TAOS_VN_STATUS_INIT
)
{
walRemoveOneOldFile
(
pVnode
->
wal
);
...
...
@@ -765,3 +769,21 @@ static int32_t vnodeWriteToCache(int32_t vgId, void *wparam, int32_t qtype, void
vnodeRelease
(
pVnode
);
return
code
;
}
static
int32_t
vnodeGetFileVersion
(
int32_t
vgId
,
uint64_t
*
fver
)
{
SVnodeObj
*
pVnode
=
vnodeAcquire
(
vgId
);
if
(
pVnode
==
NULL
)
{
vError
(
"vgId:%d, vnode not found while write to cache"
,
vgId
);
return
-
1
;
}
int32_t
code
=
0
;
if
(
pVnode
->
isCommiting
)
{
code
=
-
1
;
}
else
{
*
fver
=
pVnode
->
fversion
;
}
vnodeRelease
(
pVnode
);
return
code
;
}
src/vnode/src/vnodeWrite.c
浏览文件 @
1e94822a
...
...
@@ -288,7 +288,7 @@ static void vnodeFlowCtrlMsgToWQueue(void *param, void *tmrId) {
}
else
{
code
=
vnodePerformFlowCtrl
(
pWrite
);
if
(
code
==
0
)
{
v
Trace
(
"vgId:%d, write into vwqueue after flowctrl"
,
pVnode
->
vgId
);
v
Debug
(
"vgId:%d, write into vwqueue after flowctrl"
,
pVnode
->
vgId
);
pWrite
->
processedCount
=
0
;
taosWriteQitem
(
pVnode
->
wqueue
,
pWrite
->
qtype
,
pWrite
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录