Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN产品汪
TDengine
提交
b03ed525
T
TDengine
项目概览
CSDN产品汪
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
5
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b03ed525
编写于
7月 06, 2020
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-860] change sync confirm in sdb
上级
dc7e5963
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
56 addition
and
62 deletion
+56
-62
src/dnode/src/dnodeMWrite.c
src/dnode/src/dnodeMWrite.c
+4
-2
src/mnode/src/mnodeSdb.c
src/mnode/src/mnodeSdb.c
+52
-60
未找到文件。
src/dnode/src/dnodeMWrite.c
浏览文件 @
b03ed525
...
@@ -131,8 +131,8 @@ static void dnodeFreeMnodeWriteMsg(SMnodeMsg *pWrite) {
...
@@ -131,8 +131,8 @@ static void dnodeFreeMnodeWriteMsg(SMnodeMsg *pWrite) {
taosFreeQitem
(
pWrite
);
taosFreeQitem
(
pWrite
);
}
}
void
dnodeSendRpcMnodeWriteRsp
(
void
*
p
Raw
,
int32_t
code
)
{
void
dnodeSendRpcMnodeWriteRsp
(
void
*
p
Msg
,
int32_t
code
)
{
SMnodeMsg
*
pWrite
=
p
Raw
;
SMnodeMsg
*
pWrite
=
p
Msg
;
if
(
pWrite
==
NULL
)
return
;
if
(
pWrite
==
NULL
)
return
;
if
(
code
==
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
return
;
if
(
code
==
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
return
;
if
(
code
==
TSDB_CODE_MND_ACTION_NEED_REPROCESSED
)
{
if
(
code
==
TSDB_CODE_MND_ACTION_NEED_REPROCESSED
)
{
...
@@ -140,6 +140,8 @@ void dnodeSendRpcMnodeWriteRsp(void *pRaw, int32_t code) {
...
@@ -140,6 +140,8 @@ void dnodeSendRpcMnodeWriteRsp(void *pRaw, int32_t code) {
return
;
return
;
}
}
if
(
code
>
0
)
return
;
SRpcMsg
rpcRsp
=
{
SRpcMsg
rpcRsp
=
{
.
handle
=
pWrite
->
rpcMsg
.
handle
,
.
handle
=
pWrite
->
rpcMsg
.
handle
,
.
pCont
=
pWrite
->
rpcRsp
.
rsp
,
.
pCont
=
pWrite
->
rpcRsp
.
rsp
,
...
...
src/mnode/src/mnodeSdb.c
浏览文件 @
b03ed525
...
@@ -72,8 +72,6 @@ typedef struct {
...
@@ -72,8 +72,6 @@ typedef struct {
void
*
sync
;
void
*
sync
;
void
*
wal
;
void
*
wal
;
SSyncCfg
cfg
;
SSyncCfg
cfg
;
sem_t
sem
;
int32_t
code
;
int32_t
numOfTables
;
int32_t
numOfTables
;
SSdbTable
*
tableList
[
SDB_TABLE_MAX
];
SSdbTable
*
tableList
[
SDB_TABLE_MAX
];
pthread_mutex_t
mutex
;
pthread_mutex_t
mutex
;
...
@@ -244,27 +242,19 @@ static void sdbNotifyRole(void *ahandle, int8_t role) {
...
@@ -244,27 +242,19 @@ static void sdbNotifyRole(void *ahandle, int8_t role) {
sdbUpdateMnodeRoles
();
sdbUpdateMnodeRoles
();
}
}
FORCE_INLINE
static
void
sdbConfirmForward
(
void
*
ahandle
,
void
*
param
,
int32_t
code
)
{
static
void
sdbConfirmForward
(
void
*
ahandle
,
void
*
param
,
int32_t
code
)
{
tsSdbObj
.
code
=
code
;
SMnodeMsg
*
pMsg
=
param
;
sem_post
(
&
tsSdbObj
.
sem
);
sdbDebug
(
"forward request confirmed, version:%"
PRIu64
", result:%s"
,
(
int64_t
)
param
,
tstrerror
(
code
));
}
static
int32_t
sdbForwardToPeer
(
SWalHead
*
pHead
)
{
if
(
tsSdbObj
.
sync
==
NULL
)
return
TSDB_CODE_SUCCESS
;
int32_t
code
=
syncForwardToPeer
(
tsSdbObj
.
sync
,
pHead
,
(
void
*
)
pHead
->
version
,
TAOS_QTYPE_RPC
);
if
(
pMsg
)
{
if
(
code
>
0
)
{
sdbDebug
(
"app:%p:%p, forward request is confirmed, result:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
tstrerror
(
code
));
sdbDebug
(
"forward request is sent, version:%"
PRIu64
", code:%d"
,
pHead
->
version
,
code
);
}
sem_wait
(
&
tsSdbObj
.
sem
);
dnodeSendRpcMnodeWriteRsp
(
pMsg
,
code
);
return
tsSdbObj
.
code
;
}
return
code
;
}
}
void
sdbUpdateSync
()
{
void
sdbUpdateSync
()
{
SSyncCfg
syncCfg
=
{
0
};
SSyncCfg
syncCfg
=
{
0
};
int32_t
index
=
0
;
int32_t
index
=
0
;
SDMMnodeInfos
*
mnodes
=
dnodeGetMnodeInfos
();
SDMMnodeInfos
*
mnodes
=
dnodeGetMnodeInfos
();
for
(
int32_t
i
=
0
;
i
<
mnodes
->
nodeNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
mnodes
->
nodeNum
;
++
i
)
{
...
@@ -298,7 +288,7 @@ void sdbUpdateSync() {
...
@@ -298,7 +288,7 @@ void sdbUpdateSync() {
}
}
syncCfg
.
replica
=
index
;
syncCfg
.
replica
=
index
;
syncCfg
.
quorum
=
(
syncCfg
.
replica
==
1
)
?
1
:
2
;
syncCfg
.
quorum
=
(
syncCfg
.
replica
==
1
)
?
1
:
2
;
bool
hasThisDnode
=
false
;
bool
hasThisDnode
=
false
;
for
(
int32_t
i
=
0
;
i
<
syncCfg
.
replica
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
syncCfg
.
replica
;
++
i
)
{
...
@@ -325,10 +315,10 @@ void sdbUpdateSync() {
...
@@ -325,10 +315,10 @@ void sdbUpdateSync() {
syncInfo
.
getWalInfo
=
sdbGetWalInfo
;
syncInfo
.
getWalInfo
=
sdbGetWalInfo
;
syncInfo
.
getFileInfo
=
sdbGetFileInfo
;
syncInfo
.
getFileInfo
=
sdbGetFileInfo
;
syncInfo
.
writeToCache
=
sdbWriteToQueue
;
syncInfo
.
writeToCache
=
sdbWriteToQueue
;
syncInfo
.
confirmForward
=
sdbConfirmForward
;
syncInfo
.
confirmForward
=
sdbConfirmForward
;
syncInfo
.
notifyRole
=
sdbNotifyRole
;
syncInfo
.
notifyRole
=
sdbNotifyRole
;
tsSdbObj
.
cfg
=
syncCfg
;
tsSdbObj
.
cfg
=
syncCfg
;
if
(
tsSdbObj
.
sync
)
{
if
(
tsSdbObj
.
sync
)
{
syncReconfig
(
tsSdbObj
.
sync
,
&
syncCfg
);
syncReconfig
(
tsSdbObj
.
sync
,
&
syncCfg
);
}
else
{
}
else
{
...
@@ -339,7 +329,6 @@ void sdbUpdateSync() {
...
@@ -339,7 +329,6 @@ void sdbUpdateSync() {
int32_t
sdbInit
()
{
int32_t
sdbInit
()
{
pthread_mutex_init
(
&
tsSdbObj
.
mutex
,
NULL
);
pthread_mutex_init
(
&
tsSdbObj
.
mutex
,
NULL
);
sem_init
(
&
tsSdbObj
.
sem
,
0
,
0
);
if
(
sdbInitWriteWorker
()
!=
0
)
{
if
(
sdbInitWriteWorker
()
!=
0
)
{
return
-
1
;
return
-
1
;
...
@@ -379,7 +368,6 @@ void sdbCleanUp() {
...
@@ -379,7 +368,6 @@ void sdbCleanUp() {
tsSdbObj
.
wal
=
NULL
;
tsSdbObj
.
wal
=
NULL
;
}
}
sem_destroy
(
&
tsSdbObj
.
sem
);
pthread_mutex_destroy
(
&
tsSdbObj
.
mutex
);
pthread_mutex_destroy
(
&
tsSdbObj
.
mutex
);
}
}
...
@@ -513,24 +501,22 @@ static int sdbWrite(void *param, void *data, int type) {
...
@@ -513,24 +501,22 @@ static int sdbWrite(void *param, void *data, int type) {
assert
(
pTable
!=
NULL
);
assert
(
pTable
!=
NULL
);
pthread_mutex_lock
(
&
tsSdbObj
.
mutex
);
pthread_mutex_lock
(
&
tsSdbObj
.
mutex
);
if
(
pHead
->
version
==
0
)
{
if
(
pHead
->
version
==
0
)
{
// assign version
// assign version
tsSdbObj
.
version
++
;
tsSdbObj
.
version
++
;
pHead
->
version
=
tsSdbObj
.
version
;
pHead
->
version
=
tsSdbObj
.
version
;
}
else
{
}
else
{
// for data from WAL or forward, version may be smaller
// for data from WAL or forward, version may be smaller
if
(
pHead
->
version
<=
tsSdbObj
.
version
)
{
if
(
pHead
->
version
<=
tsSdbObj
.
version
)
{
pthread_mutex_unlock
(
&
tsSdbObj
.
mutex
);
pthread_mutex_unlock
(
&
tsSdbObj
.
mutex
);
if
(
type
==
TAOS_QTYPE_FWD
&&
tsSdbObj
.
sync
!=
NULL
)
{
sdbDebug
(
"table:%s, failed to restore %s record:%s from source(%d), version:%"
PRId64
" too large, sdb version:%"
PRId64
,
sdbDebug
(
"forward request is received, version:%"
PRIu64
" confirm it"
,
pHead
->
version
);
pTable
->
tableName
,
sdbGetActionStr
(
action
),
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
type
,
pHead
->
version
,
tsSdbObj
.
version
);
syncConfirmForward
(
tsSdbObj
.
sync
,
pHead
->
version
,
TSDB_CODE_SUCCESS
);
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
else
if
(
pHead
->
version
!=
tsSdbObj
.
version
+
1
)
{
}
else
if
(
pHead
->
version
!=
tsSdbObj
.
version
+
1
)
{
pthread_mutex_unlock
(
&
tsSdbObj
.
mutex
);
pthread_mutex_unlock
(
&
tsSdbObj
.
mutex
);
sdbError
(
"table:%s, failed to restore %s record:%s from wal, version:%"
PRId64
" too large, sdb version:%"
PRId64
,
sdbError
(
"table:%s, failed to restore %s record:%s from source(%d), version:%"
PRId64
" too large, sdb version:%"
PRId64
,
pTable
->
tableName
,
sdbGetActionStr
(
action
),
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
pHead
->
version
,
pTable
->
tableName
,
sdbGetActionStr
(
action
),
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
type
,
pHead
->
version
,
tsSdbObj
.
version
);
tsSdbObj
.
version
);
return
TSDB_CODE_MND_APP_ERROR
;
return
TSDB_CODE_MND_APP_ERROR
;
}
else
{
}
else
{
tsSdbObj
.
version
=
pHead
->
version
;
tsSdbObj
.
version
=
pHead
->
version
;
...
@@ -543,27 +529,33 @@ static int sdbWrite(void *param, void *data, int type) {
...
@@ -543,27 +529,33 @@ static int sdbWrite(void *param, void *data, int type) {
return
code
;
return
code
;
}
}
code
=
sdbForwardToPeer
(
pHead
);
// forward to peers, even it is WAL/FWD, it shall be called to update version in sync
void
*
mhandle
=
NULL
;
if
(
pOper
!=
NULL
)
mhandle
=
pOper
->
pMsg
;
int32_t
syncCode
=
syncForwardToPeer
(
tsSdbObj
.
sync
,
pHead
,
mhandle
,
TAOS_QTYPE_RPC
);
pthread_mutex_unlock
(
&
tsSdbObj
.
mutex
);
pthread_mutex_unlock
(
&
tsSdbObj
.
mutex
);
if
(
syncCode
<
0
)
{
sdbDebug
(
"table:%s, failed to forward request, result:%s action:%s record:%s version:%"
PRId64
,
pTable
->
tableName
,
tstrerror
(
syncCode
),
sdbGetActionStr
(
action
),
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
pHead
->
version
);
return
syncCode
;
}
else
if
(
syncCode
>
0
)
{
sdbDebug
(
"table:%s, forward request is sent, result:%s action:%s record:%s version:%"
PRId64
,
pTable
->
tableName
,
tstrerror
(
syncCode
),
sdbGetActionStr
(
action
),
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
pHead
->
version
);
}
else
{}
// from app, oper is created
// from app, oper is created
if
(
pOper
!=
NULL
)
{
if
(
pOper
!=
NULL
)
{
sdbTrace
(
"record from app is disposed, table:%s action:%s record:%s version:%"
PRIu64
" result:%s"
,
sdbDebug
(
"table:%s, record from app is disposed, result:%s action:%s record:%s version:%"
PRId64
,
pTable
->
tableName
,
pTable
->
tableName
,
sdbGetActionStr
(
action
),
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
pHead
->
version
,
tstrerror
(
code
),
sdbGetActionStr
(
action
),
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
pHead
->
version
);
tstrerror
(
code
));
return
syncCode
;
return
code
;
}
// from wal or forward msg, oper not created, should add into hash
if
(
tsSdbObj
.
sync
!=
NULL
)
{
sdbTrace
(
"record from wal forward is disposed, table:%s action:%s record:%s version:%"
PRIu64
" confirm it"
,
pTable
->
tableName
,
sdbGetActionStr
(
action
),
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
pHead
->
version
);
syncConfirmForward
(
tsSdbObj
.
sync
,
pHead
->
version
,
code
);
}
else
{
}
else
{
sdb
Trace
(
"record from wal restore is disposed, table:%s action:%s record:%s version:%"
PRIu
64
,
pTable
->
tableName
,
sdb
Debug
(
"table:%s, record from wal/fwd is disposed, result:%s action:%s record:%s version:%"
PRId
64
,
pTable
->
tableName
,
sdbGetActionStr
(
action
),
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
pHead
->
version
);
tstrerror
(
code
),
sdbGetActionStr
(
action
),
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
pHead
->
version
);
}
}
// from wal or forward msg, oper not created, should add into hash
if
(
action
==
SDB_ACTION_INSERT
)
{
if
(
action
==
SDB_ACTION_INSERT
)
{
SSdbOper
oper
=
{.
rowSize
=
pHead
->
len
,
.
rowData
=
pHead
->
cont
,
.
table
=
pTable
};
SSdbOper
oper
=
{.
rowSize
=
pHead
->
len
,
.
rowData
=
pHead
->
cont
,
.
table
=
pTable
};
code
=
(
*
pTable
->
decodeFp
)(
&
oper
);
code
=
(
*
pTable
->
decodeFp
)(
&
oper
);
...
@@ -944,17 +936,16 @@ static void *sdbWorkerFp(void *param) {
...
@@ -944,17 +936,16 @@ static void *sdbWorkerFp(void *param) {
if
(
type
==
TAOS_QTYPE_RPC
)
{
if
(
type
==
TAOS_QTYPE_RPC
)
{
pOper
=
(
SSdbOper
*
)
item
;
pOper
=
(
SSdbOper
*
)
item
;
pHead
=
(
void
*
)
pOper
+
sizeof
(
SSdbOper
)
+
SDB_SYNC_HACK
;
pHead
=
(
void
*
)
pOper
+
sizeof
(
SSdbOper
)
+
SDB_SYNC_HACK
;
if
(
pOper
->
pMsg
!=
NULL
)
{
sdbDebug
(
"app:%p:%p, table:%s record:%p:%s version:%"
PRIu64
", will be processed in sdb queue"
,
pOper
->
pMsg
->
rpcMsg
.
ahandle
,
pOper
->
pMsg
,
((
SSdbTable
*
)
pOper
->
table
)
->
tableName
,
pOper
->
pObj
,
sdbGetKeyStr
(
pOper
->
table
,
pHead
->
cont
),
pHead
->
version
);
}
}
else
{
}
else
{
pHead
=
(
SWalHead
*
)
item
;
pHead
=
(
SWalHead
*
)
item
;
pOper
=
NULL
;
pOper
=
NULL
;
}
}
if
(
pOper
!=
NULL
&&
pOper
->
pMsg
!=
NULL
)
{
sdbDebug
(
"app:%p:%p, table:%s record:%p:%s version:%"
PRIu64
", will be processed in sdb queue"
,
pOper
->
pMsg
->
rpcMsg
.
ahandle
,
pOper
->
pMsg
,
((
SSdbTable
*
)
pOper
->
table
)
->
tableName
,
pOper
->
pObj
,
sdbGetKeyStr
(
pOper
->
table
,
pHead
->
cont
),
pHead
->
version
);
}
int32_t
code
=
sdbWrite
(
pOper
,
pHead
,
type
);
int32_t
code
=
sdbWrite
(
pOper
,
pHead
,
type
);
if
(
pOper
)
pOper
->
retCode
=
code
;
if
(
pOper
)
pOper
->
retCode
=
code
;
}
}
...
@@ -965,23 +956,24 @@ static void *sdbWorkerFp(void *param) {
...
@@ -965,23 +956,24 @@ static void *sdbWorkerFp(void *param) {
taosResetQitems
(
tsSdbWriteQall
);
taosResetQitems
(
tsSdbWriteQall
);
for
(
int32_t
i
=
0
;
i
<
numOfMsgs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfMsgs
;
++
i
)
{
taosGetQitem
(
tsSdbWriteQall
,
&
type
,
&
item
);
taosGetQitem
(
tsSdbWriteQall
,
&
type
,
&
item
);
if
(
type
==
TAOS_QTYPE_RPC
)
{
if
(
type
==
TAOS_QTYPE_RPC
)
{
pOper
=
(
SSdbOper
*
)
item
;
pOper
=
(
SSdbOper
*
)
item
;
if
(
pOper
!=
NULL
&&
pOper
->
cb
!
=
NULL
)
{
if
(
pOper
=
=
NULL
)
{
sdbTrace
(
"app:%p:%p, will do callback func, index:%d"
,
pOper
->
pMsg
->
rpcMsg
.
ahandle
,
pOper
->
pMsg
,
i
);
taosFreeQitem
(
item
);
pOper
->
retCode
=
(
*
pOper
->
cb
)(
pOper
->
pMsg
,
pOper
->
retCode
)
;
continue
;
}
}
if
(
pOper
!=
NULL
&&
pOper
->
pMsg
!=
NULL
)
{
if
(
pOper
->
cb
!=
NULL
)
{
sdbTrace
(
"app:%p:%p, msg is processed, result:%s"
,
pOper
->
pMsg
->
rpcMsg
.
ahandle
,
pOper
->
pMsg
,
sdbTrace
(
"app:%p:%p, will do callback func, index:%d"
,
pOper
->
pMsg
->
rpcMsg
.
ahandle
,
pOper
->
pMsg
,
i
);
tstrerror
(
pOper
->
retCode
));
pOper
->
retCode
=
(
*
pOper
->
cb
)(
pOper
->
pMsg
,
pOper
->
retCode
);
}
if
(
pOper
!=
NULL
)
{
sdbDecRef
(
pOper
->
table
,
pOper
->
pObj
);
}
}
dnodeSendRpcMnodeWriteRsp
(
pOper
->
pMsg
,
pOper
->
retCode
);
dnodeSendRpcMnodeWriteRsp
(
pOper
->
pMsg
,
pOper
->
retCode
);
sdbDecRef
(
pOper
->
table
,
pOper
->
pObj
);
}
else
if
(
type
==
TAOS_QTYPE_FWD
)
{
syncConfirmForward
(
tsSdbObj
.
sync
,
pHead
->
version
,
TSDB_CODE_SUCCESS
);
}
else
{
}
}
taosFreeQitem
(
item
);
taosFreeQitem
(
item
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录