Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f24703f8
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
f24703f8
编写于
1月 04, 2023
作者:
D
dapan1121
提交者:
GitHub
1月 04, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19308 from taosdata/enh/TD-21211-3.0
enh: sma assert/log optimization
上级
4bd99bb7
8ab9acee
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
229 addition
and
283 deletion
+229
-283
source/dnode/vnode/src/sma/smaCommit.c
source/dnode/vnode/src/sma/smaCommit.c
+22
-73
source/dnode/vnode/src/sma/smaEnv.c
source/dnode/vnode/src/sma/smaEnv.c
+37
-14
source/dnode/vnode/src/sma/smaFS.c
source/dnode/vnode/src/sma/smaFS.c
+6
-83
source/dnode/vnode/src/sma/smaOpen.c
source/dnode/vnode/src/sma/smaOpen.c
+29
-20
source/dnode/vnode/src/sma/smaRollup.c
source/dnode/vnode/src/sma/smaRollup.c
+132
-92
source/libs/tfs/src/tfs.c
source/libs/tfs/src/tfs.c
+3
-1
未找到文件。
source/dnode/vnode/src/sma/smaCommit.c
浏览文件 @
f24703f8
...
@@ -116,68 +116,6 @@ _exit:
...
@@ -116,68 +116,6 @@ _exit:
return
code
;
return
code
;
}
}
// SQTaskFile ======================================================
/**
* @brief At most time, there is only one qtaskinfo file committed latest in aTaskFile. Sometimes, there would be
* multiple qtaskinfo files supporting snapshot replication.
*
* @param pSma
* @param pStat
* @return int32_t
*/
static
int32_t
tdUpdateQTaskInfoFiles
(
SSma
*
pSma
,
SRSmaStat
*
pStat
)
{
#if 0
SVnode *pVnode = pSma->pVnode;
SRSmaFS *pFS = RSMA_FS(pStat);
int64_t committed = pStat->commitAppliedVer;
int64_t fsMaxVer = -1;
char qTaskInfoFullName[TSDB_FILENAME_LEN];
taosWLockLatch(RSMA_FS_LOCK(pStat));
for (int32_t i = 0; i < taosArrayGetSize(pFS->aQTaskInf);) {
SQTaskFile *pTaskF = taosArrayGet(pFS->aQTaskInf, i);
int32_t oldVal = atomic_fetch_sub_32(&pTaskF->nRef, 1);
if ((oldVal <= 1) && (pTaskF->version < committed)) {
tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), pTaskF->version, tfsGetPrimaryPath(pVnode->pTfs), qTaskInfoFullName);
if (taosRemoveFile(qTaskInfoFullName) < 0) {
smaWarn("vgId:%d, cleanup qinf, committed %" PRIi64 ", failed to remove %s since %s", TD_VID(pVnode), committed,
qTaskInfoFullName, tstrerror(TAOS_SYSTEM_ERROR(errno)));
} else {
smaDebug("vgId:%d, cleanup qinf, committed %" PRIi64 ", success to remove %s", TD_VID(pVnode), committed,
qTaskInfoFullName);
}
taosArrayRemove(pFS->aQTaskInf, i);
continue;
}
++i;
}
if (taosArrayGetSize(pFS->aQTaskInf) > 0) {
fsMaxVer = ((SQTaskFile *)taosArrayGetLast(pFS->aQTaskInf))->version;
}
if (fsMaxVer < committed) {
tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), committed, tfsGetPrimaryPath(pVnode->pTfs), qTaskInfoFullName);
if (taosCheckExistFile(qTaskInfoFullName)) {
SQTaskFile qFile = {.nRef = 1, .padding = 0, .version = committed, .size = 0};
if (!taosArrayPush(pFS->aQTaskInf, &qFile)) {
taosWUnLockLatch(RSMA_FS_LOCK(pStat));
terrno = TSDB_CODE_OUT_OF_MEMORY;
return TSDB_CODE_FAILED;
}
}
} else {
smaDebug("vgId:%d, update qinf, no need as committed %" PRIi64 " not larger than fsMaxVer %" PRIi64, TD_VID(pVnode),
committed, fsMaxVer);
}
taosWUnLockLatch(RSMA_FS_LOCK(pStat));
#endif
return
TSDB_CODE_SUCCESS
;
}
/**
/**
* @brief Rsma async commit implementation(only do some necessary light weighted task)
* @brief Rsma async commit implementation(only do some necessary light weighted task)
* 1) set rsma stat TASK_TRIGGER_STAT_PAUSED
* 1) set rsma stat TASK_TRIGGER_STAT_PAUSED
...
@@ -187,7 +125,8 @@ static int32_t tdUpdateQTaskInfoFiles(SSma *pSma, SRSmaStat *pStat) {
...
@@ -187,7 +125,8 @@ static int32_t tdUpdateQTaskInfoFiles(SSma *pSma, SRSmaStat *pStat) {
* @return int32_t
* @return int32_t
*/
*/
static
int32_t
tdProcessRSmaAsyncPreCommitImpl
(
SSma
*
pSma
)
{
static
int32_t
tdProcessRSmaAsyncPreCommitImpl
(
SSma
*
pSma
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
int32_t
lino
=
0
;
SSmaEnv
*
pEnv
=
SMA_RSMA_ENV
(
pSma
);
SSmaEnv
*
pEnv
=
SMA_RSMA_ENV
(
pSma
);
if
(
!
pEnv
)
{
if
(
!
pEnv
)
{
...
@@ -208,7 +147,11 @@ static int32_t tdProcessRSmaAsyncPreCommitImpl(SSma *pSma) {
...
@@ -208,7 +147,11 @@ static int32_t tdProcessRSmaAsyncPreCommitImpl(SSma *pSma) {
}
}
}
}
pRSmaStat
->
commitAppliedVer
=
pSma
->
pVnode
->
state
.
applied
;
pRSmaStat
->
commitAppliedVer
=
pSma
->
pVnode
->
state
.
applied
;
// ASSERT(pRSmaStat->commitAppliedVer > 0);
if
(
ASSERTS
(
pRSmaStat
->
commitAppliedVer
>=
0
,
"commit applied version %"
PRIi64
" < 0"
,
pRSmaStat
->
commitAppliedVer
))
{
code
=
TSDB_CODE_APP_ERROR
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
// step 2: wait for all triggered fetch tasks to finish
// step 2: wait for all triggered fetch tasks to finish
nLoops
=
0
;
nLoops
=
0
;
...
@@ -242,9 +185,9 @@ static int32_t tdProcessRSmaAsyncPreCommitImpl(SSma *pSma) {
...
@@ -242,9 +185,9 @@ static int32_t tdProcessRSmaAsyncPreCommitImpl(SSma *pSma) {
}
}
}
}
smaInfo
(
"vgId:%d, rsma commit, all items are consumed, TID:%p"
,
SMA_VID
(
pSma
),
(
void
*
)
taosGetSelfPthreadId
());
smaInfo
(
"vgId:%d, rsma commit, all items are consumed, TID:%p"
,
SMA_VID
(
pSma
),
(
void
*
)
taosGetSelfPthreadId
());
if
((
code
=
tdRSmaPersistExecImpl
(
pRSmaStat
,
RSMA_INFO_HASH
(
pRSmaStat
)))
!=
0
)
{
code
=
tdRSmaPersistExecImpl
(
pRSmaStat
,
RSMA_INFO_HASH
(
pRSmaStat
));
return
code
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
}
smaInfo
(
"vgId:%d, rsma commit, operator state committed, TID:%p"
,
SMA_VID
(
pSma
),
(
void
*
)
taosGetSelfPthreadId
());
smaInfo
(
"vgId:%d, rsma commit, operator state committed, TID:%p"
,
SMA_VID
(
pSma
),
(
void
*
)
taosGetSelfPthreadId
());
#if 0 // consuming task of qTaskInfo clone
#if 0 // consuming task of qTaskInfo clone
...
@@ -252,8 +195,6 @@ static int32_t tdProcessRSmaAsyncPreCommitImpl(SSma *pSma) {
...
@@ -252,8 +195,6 @@ static int32_t tdProcessRSmaAsyncPreCommitImpl(SSma *pSma) {
// lock
// lock
taosWLockLatch(SMA_ENV_LOCK(pEnv));
taosWLockLatch(SMA_ENV_LOCK(pEnv));
ASSERT(RSMA_INFO_HASH(pRSmaStat));
void *pIter = taosHashIterate(RSMA_INFO_HASH(pRSmaStat), NULL);
void *pIter = taosHashIterate(RSMA_INFO_HASH(pRSmaStat), NULL);
while (pIter) {
while (pIter) {
...
@@ -271,9 +212,19 @@ static int32_t tdProcessRSmaAsyncPreCommitImpl(SSma *pSma) {
...
@@ -271,9 +212,19 @@ static int32_t tdProcessRSmaAsyncPreCommitImpl(SSma *pSma) {
// all rsma results are written completely
// all rsma results are written completely
STsdb
*
pTsdb
=
NULL
;
STsdb
*
pTsdb
=
NULL
;
if
((
pTsdb
=
VND_RSMA1
(
pSma
->
pVnode
)))
tsdbPrepareCommit
(
pTsdb
);
if
((
pTsdb
=
VND_RSMA1
(
pSma
->
pVnode
)))
{
if
((
pTsdb
=
VND_RSMA2
(
pSma
->
pVnode
)))
tsdbPrepareCommit
(
pTsdb
);
code
=
tsdbPrepareCommit
(
pTsdb
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
if
((
pTsdb
=
VND_RSMA2
(
pSma
->
pVnode
)))
{
code
=
tsdbPrepareCommit
(
pTsdb
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
_exit:
if
(
code
)
{
smaError
(
"vgId:%d, %s failed at line %d since %s"
,
SMA_VID
(
pSma
),
__func__
,
lino
,
tstrerror
(
code
));
}
return
code
;
return
code
;
}
}
...
@@ -360,8 +311,6 @@ static int32_t tdProcessRSmaAsyncPostCommitImpl(SSma *pSma) {
...
@@ -360,8 +311,6 @@ static int32_t tdProcessRSmaAsyncPostCommitImpl(SSma *pSma) {
taosWUnLockLatch
(
SMA_ENV_LOCK
(
pEnv
));
taosWUnLockLatch
(
SMA_ENV_LOCK
(
pEnv
));
}
}
tdUpdateQTaskInfoFiles
(
pSma
,
pRSmaStat
);
atomic_store_8
(
RSMA_COMMIT_STAT
(
pRSmaStat
),
0
);
atomic_store_8
(
RSMA_COMMIT_STAT
(
pRSmaStat
),
0
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
...
source/dnode/vnode/src/sma/smaEnv.c
浏览文件 @
f24703f8
...
@@ -131,7 +131,7 @@ static int32_t tdNewSmaEnv(SSma *pSma, int8_t smaType, SSmaEnv **ppEnv) {
...
@@ -131,7 +131,7 @@ static int32_t tdNewSmaEnv(SSma *pSma, int8_t smaType, SSmaEnv **ppEnv) {
(
smaType
==
TSDB_SMA_TYPE_TIME_RANGE
)
?
atomic_store_ptr
(
&
SMA_TSMA_ENV
(
pSma
),
*
ppEnv
)
(
smaType
==
TSDB_SMA_TYPE_TIME_RANGE
)
?
atomic_store_ptr
(
&
SMA_TSMA_ENV
(
pSma
),
*
ppEnv
)
:
atomic_store_ptr
(
&
SMA_RSMA_ENV
(
pSma
),
*
ppEnv
);
:
atomic_store_ptr
(
&
SMA_RSMA_ENV
(
pSma
),
*
ppEnv
);
if
(
tdInitSmaStat
(
&
SMA_ENV_STAT
(
pEnv
),
smaType
,
pSma
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
(
terrno
=
tdInitSmaStat
(
&
SMA_ENV_STAT
(
pEnv
),
smaType
,
pSma
)
)
!=
TSDB_CODE_SUCCESS
)
{
tdFreeSmaEnv
(
pEnv
);
tdFreeSmaEnv
(
pEnv
);
*
ppEnv
=
NULL
;
*
ppEnv
=
NULL
;
(
smaType
==
TSDB_SMA_TYPE_TIME_RANGE
)
?
atomic_store_ptr
(
&
SMA_TSMA_ENV
(
pSma
),
NULL
)
(
smaType
==
TSDB_SMA_TYPE_TIME_RANGE
)
?
atomic_store_ptr
(
&
SMA_TSMA_ENV
(
pSma
),
NULL
)
...
@@ -193,10 +193,16 @@ static void tRSmaInfoHashFreeNode(void *data) {
...
@@ -193,10 +193,16 @@ static void tRSmaInfoHashFreeNode(void *data) {
}
}
static
int32_t
tdInitSmaStat
(
SSmaStat
**
pSmaStat
,
int8_t
smaType
,
const
SSma
*
pSma
)
{
static
int32_t
tdInitSmaStat
(
SSmaStat
**
pSmaStat
,
int8_t
smaType
,
const
SSma
*
pSma
)
{
ASSERT
(
pSmaStat
!=
NULL
);
int32_t
code
=
0
;
int32_t
lino
=
0
;
if
(
ASSERTS
(
pSmaStat
!=
NULL
,
"pSmaStat is NULL"
))
{
terrno
=
TSDB_CODE_RSMA_INVALID_ENV
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
if
(
*
pSmaStat
)
{
// no lock
if
(
*
pSmaStat
)
{
// no lock
return
TSDB_CODE_SUCCESS
;
return
code
;
// success, return directly
}
}
/**
/**
...
@@ -207,8 +213,8 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS
...
@@ -207,8 +213,8 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS
if
(
!
(
*
pSmaStat
))
{
if
(
!
(
*
pSmaStat
))
{
*
pSmaStat
=
(
SSmaStat
*
)
taosMemoryCalloc
(
1
,
sizeof
(
SSmaStat
)
+
sizeof
(
TdThread
)
*
tsNumOfVnodeRsmaThreads
);
*
pSmaStat
=
(
SSmaStat
*
)
taosMemoryCalloc
(
1
,
sizeof
(
SSmaStat
)
+
sizeof
(
TdThread
)
*
tsNumOfVnodeRsmaThreads
);
if
(
!
(
*
pSmaStat
))
{
if
(
!
(
*
pSmaStat
))
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
code
=
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_FAILED
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
}
}
if
(
smaType
==
TSDB_SMA_TYPE_ROLLUP
)
{
if
(
smaType
==
TSDB_SMA_TYPE_ROLLUP
)
{
...
@@ -224,7 +230,8 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS
...
@@ -224,7 +230,8 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS
if
(
refId
<
0
)
{
if
(
refId
<
0
)
{
smaError
(
"vgId:%d, taosAddRef refId:%"
PRIi64
" to rsetId rsetId:%d max:%d failed since:%s"
,
SMA_VID
(
pSma
),
smaError
(
"vgId:%d, taosAddRef refId:%"
PRIi64
" to rsetId rsetId:%d max:%d failed since:%s"
,
SMA_VID
(
pSma
),
refId
,
smaMgmt
.
rsetId
,
SMA_MGMT_REF_NUM
,
tstrerror
(
terrno
));
refId
,
smaMgmt
.
rsetId
,
SMA_MGMT_REF_NUM
,
tstrerror
(
terrno
));
return
TSDB_CODE_FAILED
;
code
=
terrno
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
else
{
}
else
{
smaDebug
(
"vgId:%d, taosAddRef refId:%"
PRIi64
" to rsetId rsetId:%d max:%d succeed"
,
SMA_VID
(
pSma
),
refId
,
smaDebug
(
"vgId:%d, taosAddRef refId:%"
PRIi64
" to rsetId rsetId:%d max:%d succeed"
,
SMA_VID
(
pSma
),
refId
,
smaMgmt
.
rsetId
,
SMA_MGMT_REF_NUM
);
smaMgmt
.
rsetId
,
SMA_MGMT_REF_NUM
);
...
@@ -235,22 +242,30 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS
...
@@ -235,22 +242,30 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS
RSMA_INFO_HASH
(
pRSmaStat
)
=
taosHashInit
(
RSMA_INFO_HASH
(
pRSmaStat
)
=
taosHashInit
(
RSMA_TASK_INFO_HASH_SLOT
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
true
,
HASH_ENTRY_LOCK
);
RSMA_TASK_INFO_HASH_SLOT
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
true
,
HASH_ENTRY_LOCK
);
if
(
!
RSMA_INFO_HASH
(
pRSmaStat
))
{
if
(
!
RSMA_INFO_HASH
(
pRSmaStat
))
{
return
TSDB_CODE_FAILED
;
code
=
terrno
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
}
taosHashSetFreeFp
(
RSMA_INFO_HASH
(
pRSmaStat
),
tRSmaInfoHashFreeNode
);
taosHashSetFreeFp
(
RSMA_INFO_HASH
(
pRSmaStat
),
tRSmaInfoHashFreeNode
);
if
(
tdRsmaStartExecutor
(
pSma
)
<
0
)
{
if
(
tdRsmaStartExecutor
(
pSma
)
<
0
)
{
return
TSDB_CODE_FAILED
;
code
=
terrno
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
}
taosInitRWLatch
(
RSMA_FS_LOCK
(
pRSmaStat
));
taosInitRWLatch
(
RSMA_FS_LOCK
(
pRSmaStat
));
}
else
if
(
smaType
==
TSDB_SMA_TYPE_TIME_RANGE
)
{
}
else
if
(
smaType
==
TSDB_SMA_TYPE_TIME_RANGE
)
{
// TODO
// TODO
}
else
{
}
else
{
ASSERT
(
0
);
ASSERTS
(
0
,
"unknown smaType:%"
PRIi8
,
smaType
);
code
=
TSDB_CODE_APP_ERROR
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
}
}
}
return
TSDB_CODE_SUCCESS
;
_exit:
if
(
code
)
{
smaError
(
"vgId:%d, %s failed at line %d since %s"
,
SMA_VID
(
pSma
),
__func__
,
lino
,
tstrerror
(
code
));
}
return
code
;
}
}
static
void
tdDestroyTSmaStat
(
STSmaStat
*
pStat
)
{
static
void
tdDestroyTSmaStat
(
STSmaStat
*
pStat
)
{
...
@@ -339,7 +354,10 @@ static int32_t tdDestroySmaState(SSmaStat *pSmaStat, int8_t smaType) {
...
@@ -339,7 +354,10 @@ static int32_t tdDestroySmaState(SSmaStat *pSmaStat, int8_t smaType) {
smaDebug
(
"vgId:%d, remove refId:%"
PRIi64
" from rsmaRef:%"
PRIi32
" succeed"
,
vid
,
refId
,
smaMgmt
.
rsetId
);
smaDebug
(
"vgId:%d, remove refId:%"
PRIi64
" from rsmaRef:%"
PRIi32
" succeed"
,
vid
,
refId
,
smaMgmt
.
rsetId
);
}
}
}
else
{
}
else
{
ASSERT
(
0
);
ASSERTS
(
0
,
"unknown smaType:%"
PRIi8
,
smaType
);
terrno
=
TSDB_CODE_APP_ERROR
;
smaError
(
"%s failed at line %d since %s"
,
__func__
,
__LINE__
,
terrstr
());
return
-
1
;
}
}
}
}
return
0
;
return
0
;
...
@@ -348,7 +366,7 @@ static int32_t tdDestroySmaState(SSmaStat *pSmaStat, int8_t smaType) {
...
@@ -348,7 +366,7 @@ static int32_t tdDestroySmaState(SSmaStat *pSmaStat, int8_t smaType) {
int32_t
tdLockSma
(
SSma
*
pSma
)
{
int32_t
tdLockSma
(
SSma
*
pSma
)
{
int
code
=
taosThreadMutexLock
(
&
pSma
->
mutex
);
int
code
=
taosThreadMutexLock
(
&
pSma
->
mutex
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
smaError
(
"vgId:%d, failed to lock
td
since %s"
,
SMA_VID
(
pSma
),
strerror
(
errno
));
smaError
(
"vgId:%d, failed to lock since %s"
,
SMA_VID
(
pSma
),
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
return
-
1
;
}
}
...
@@ -357,12 +375,17 @@ int32_t tdLockSma(SSma *pSma) {
...
@@ -357,12 +375,17 @@ int32_t tdLockSma(SSma *pSma) {
}
}
int32_t
tdUnLockSma
(
SSma
*
pSma
)
{
int32_t
tdUnLockSma
(
SSma
*
pSma
)
{
ASSERT
(
SMA_LOCKED
(
pSma
));
if
(
ASSERTS
(
SMA_LOCKED
(
pSma
),
"pSma %p is not locked:%d"
,
pSma
,
pSma
->
locked
))
{
terrno
=
TSDB_CODE_APP_ERROR
;
smaError
(
"vgId:%d, failed to unlock since %s"
,
SMA_VID
(
pSma
),
tstrerror
(
terrno
));
return
-
1
;
}
pSma
->
locked
=
false
;
pSma
->
locked
=
false
;
int
code
=
taosThreadMutexUnlock
(
&
pSma
->
mutex
);
int
code
=
taosThreadMutexUnlock
(
&
pSma
->
mutex
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
smaError
(
"vgId:%d, failed to unlock td since %s"
,
SMA_VID
(
pSma
),
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
smaError
(
"vgId:%d, failed to unlock since %s"
,
SMA_VID
(
pSma
),
strerror
(
errno
));
return
-
1
;
return
-
1
;
}
}
return
0
;
return
0
;
...
...
source/dnode/vnode/src/sma/smaFS.c
浏览文件 @
f24703f8
...
@@ -77,7 +77,7 @@ static int32_t tsdbBinaryToFS(uint8_t *pData, int64_t nData, SRSmaFS *pFS) {
...
@@ -77,7 +77,7 @@ static int32_t tsdbBinaryToFS(uint8_t *pData, int64_t nData, SRSmaFS *pFS) {
int32_t
nt
=
tdRSmaGetQTaskF
(
pData
+
n
,
&
qTaskF
);
int32_t
nt
=
tdRSmaGetQTaskF
(
pData
+
n
,
&
qTaskF
);
if
(
nt
<
0
)
{
if
(
nt
<
0
)
{
code
=
TSDB_CODE_
OUT_OF_MEMORY
;
code
=
TSDB_CODE_
FILE_CORRUPTED
;
goto
_exit
;
goto
_exit
;
}
}
...
@@ -88,7 +88,11 @@ static int32_t tsdbBinaryToFS(uint8_t *pData, int64_t nData, SRSmaFS *pFS) {
...
@@ -88,7 +88,11 @@ static int32_t tsdbBinaryToFS(uint8_t *pData, int64_t nData, SRSmaFS *pFS) {
}
}
}
}
ASSERT
(
n
+
sizeof
(
TSCKSUM
)
==
nData
);
if
(
ASSERTS
(
n
+
sizeof
(
TSCKSUM
)
==
nData
,
"n:%d + sizeof(TSCKSUM):%d != nData:%d"
,
n
,
(
int32_t
)
sizeof
(
TSCKSUM
),
nData
))
{
code
=
TSDB_CODE_FILE_CORRUPTED
;
goto
_exit
;
}
_exit:
_exit:
return
code
;
return
code
;
...
@@ -545,87 +549,6 @@ int32_t tdRSmaFSUpsertQTaskFile(SSma *pSma, SRSmaFS *pFS, SQTaskFile *qTaskFile,
...
@@ -545,87 +549,6 @@ int32_t tdRSmaFSUpsertQTaskFile(SSma *pSma, SRSmaFS *pFS, SQTaskFile *qTaskFile,
_exit:
_exit:
return
code
;
return
code
;
}
}
#if 0
int32_t tdRSmaFSRef(SSma *pSma, SRSmaStat *pStat, int64_t suid, int8_t level, int64_t version) {
SArray *aQTaskInf = RSMA_FS(pStat)->aQTaskInf;
SQTaskFile qTaskF = {.level = level, .suid = suid, .version = version};
SQTaskFile *pTaskF = NULL;
int32_t oldVal = 0;
taosRLockLatch(RSMA_FS_LOCK(pStat));
if (suid > 0 && level > 0) {
ASSERT(version > 0);
if ((pTaskF = taosArraySearch(aQTaskInf, &qTaskF, tdQTaskInfCmprFn1, TD_EQ))) {
oldVal = atomic_fetch_add_32(&pTaskF->nRef, 1);
ASSERT(oldVal > 0);
}
} else {
// ref all
int32_t size = taosArrayGetSize(aQTaskInf);
for (int32_t i = 0; i < size; ++i) {
pTaskF = TARRAY_GET_ELEM(aQTaskInf, i);
oldVal = atomic_fetch_add_32(&pTaskF->nRef, 1);
ASSERT(oldVal > 0);
}
}
taosRUnLockLatch(RSMA_FS_LOCK(pStat));
return oldVal;
}
void tdRSmaFSUnRef(SSma *pSma, SRSmaStat *pStat, int64_t suid, int8_t level, int64_t version) {
SVnode *pVnode = pSma->pVnode;
SArray *aQTaskInf = RSMA_FS(pStat)->aQTaskInf;
char qTaskFullName[TSDB_FILENAME_LEN];
SQTaskFile qTaskF = {.level = level, .suid = suid, .version = version};
SQTaskFile *pTaskF = NULL;
int32_t idx = -1;
taosWLockLatch(RSMA_FS_LOCK(pStat));
if (suid > 0 && level > 0) {
ASSERT(version > 0);
if ((idx = taosArraySearchIdx(aQTaskInf, &qTaskF, tdQTaskInfCmprFn1, TD_EQ)) >= 0) {
ASSERT(idx < taosArrayGetSize(aQTaskInf));
pTaskF = taosArrayGet(aQTaskInf, idx);
if (atomic_sub_fetch_32(&pTaskF->nRef, 1) <= 0) {
tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), pTaskF->suid, level, pTaskF->version,
tfsGetPrimaryPath(pVnode->pTfs), qTaskFullName);
if (taosRemoveFile(qTaskFullName) < 0) {
smaWarn("vgId:%d, failed to remove %s since %s", TD_VID(pVnode), qTaskFullName,
tstrerror(TAOS_SYSTEM_ERROR(errno)));
} else {
smaDebug("vgId:%d, success to remove %s", TD_VID(pVnode), qTaskFullName);
}
taosArrayRemove(aQTaskInf, idx);
}
}
} else {
for (int32_t i = 0; i < taosArrayGetSize(aQTaskInf);) {
pTaskF = TARRAY_GET_ELEM(aQTaskInf, i);
int32_t nRef = INT32_MAX;
if (pTaskF->version == version) {
nRef = atomic_sub_fetch_32(&pTaskF->nRef, 1);
} else if (pTaskF->version < version) {
nRef = atomic_load_32(&pTaskF->nRef);
}
if (nRef <= 0) {
tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), pTaskF->suid, pTaskF->level, pTaskF->version,
tfsGetPrimaryPath(pVnode->pTfs), qTaskFullName);
if (taosRemoveFile(qTaskFullName) < 0) {
smaWarn("vgId:%d, failed to remove %s since %s", TD_VID(pVnode), qTaskFullName,
tstrerror(TAOS_SYSTEM_ERROR(errno)));
} else {
smaDebug("vgId:%d, success to remove %s", TD_VID(pVnode), qTaskFullName);
}
taosArrayRemove(aQTaskInf, i);
continue;
}
++i;
}
}
taosWUnLockLatch(RSMA_FS_LOCK(pStat));
}
#endif
int32_t
tdRSmaFSRef
(
SSma
*
pSma
,
SRSmaFS
*
pFS
)
{
int32_t
tdRSmaFSRef
(
SSma
*
pSma
,
SRSmaFS
*
pFS
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
...
...
source/dnode/vnode/src/sma/smaOpen.c
浏览文件 @
f24703f8
...
@@ -34,13 +34,16 @@ static int32_t rsmaRestore(SSma *pSma);
...
@@ -34,13 +34,16 @@ static int32_t rsmaRestore(SSma *pSma);
SRetention *r = (SRetention *)VND_RETENTIONS(v) + l; \
SRetention *r = (SRetention *)VND_RETENTIONS(v) + l; \
if (!RETENTION_VALID(r)) { \
if (!RETENTION_VALID(r)) { \
if (l == 0) { \
if (l == 0) { \
goto _err; \
code = TSDB_CODE_INVALID_PARA; \
TSDB_CHECK_CODE(code, lino, _exit); \
} \
} \
break; \
break; \
} \
} \
smaSetKeepCfg(v, &keepCfg, pCfg, TSDB_TYPE_RSMA_L##l); \
code = smaSetKeepCfg(v, &keepCfg, pCfg, TSDB_TYPE_RSMA_L##l); \
TSDB_CHECK_CODE(code, lino, _exit); \
if (tsdbOpen(v, &SMA_RSMA_TSDB##l(pSma), VNODE_RSMA##l##_DIR, &keepCfg, rollback) < 0) { \
if (tsdbOpen(v, &SMA_RSMA_TSDB##l(pSma), VNODE_RSMA##l##_DIR, &keepCfg, rollback) < 0) { \
goto _err; \
code = terrno; \
TSDB_CHECK_CODE(code, lino, _exit); \
} \
} \
} while (0)
} while (0)
...
@@ -68,12 +71,10 @@ static int32_t smaEvalDays(SVnode *pVnode, SRetention *r, int8_t level, int8_t p
...
@@ -68,12 +71,10 @@ static int32_t smaEvalDays(SVnode *pVnode, SRetention *r, int8_t level, int8_t p
days
=
keepDuration
;
days
=
keepDuration
;
}
}
if
(
level
==
TSDB_RETENTION_L0
)
{
if
(
level
<
TSDB_RETENTION_L1
||
level
>
TSDB_RETENTION_L2
)
{
goto
end
;
goto
_exit
;
}
}
ASSERT
(
level
>=
TSDB_RETENTION_L1
&&
level
<=
TSDB_RETENTION_L2
);
freqDuration
=
convertTimeFromPrecisionToUnit
((
r
+
level
)
->
freq
,
precision
,
TIME_UNIT_MINUTE
);
freqDuration
=
convertTimeFromPrecisionToUnit
((
r
+
level
)
->
freq
,
precision
,
TIME_UNIT_MINUTE
);
keepDuration
=
convertTimeFromPrecisionToUnit
((
r
+
level
)
->
keep
,
precision
,
TIME_UNIT_MINUTE
);
keepDuration
=
convertTimeFromPrecisionToUnit
((
r
+
level
)
->
keep
,
precision
,
TIME_UNIT_MINUTE
);
...
@@ -91,16 +92,18 @@ static int32_t smaEvalDays(SVnode *pVnode, SRetention *r, int8_t level, int8_t p
...
@@ -91,16 +92,18 @@ static int32_t smaEvalDays(SVnode *pVnode, SRetention *r, int8_t level, int8_t p
if
(
days
<
freqDuration
)
{
if
(
days
<
freqDuration
)
{
days
=
freqDuration
;
days
=
freqDuration
;
}
}
end
:
_exit
:
smaInfo
(
"vgId:%d, evaluated duration for level %d is %d, raw val:%d"
,
TD_VID
(
pVnode
),
level
+
1
,
days
,
duration
);
smaInfo
(
"vgId:%d, evaluated duration for level %d is %d, raw val:%d"
,
TD_VID
(
pVnode
),
level
+
1
,
days
,
duration
);
return
days
;
return
days
;
}
}
int
smaSetKeepCfg
(
SVnode
*
pVnode
,
STsdbKeepCfg
*
pKeepCfg
,
STsdbCfg
*
pCfg
,
int
type
)
{
int
smaSetKeepCfg
(
SVnode
*
pVnode
,
STsdbKeepCfg
*
pKeepCfg
,
STsdbCfg
*
pCfg
,
int
type
)
{
terrno
=
0
;
pKeepCfg
->
precision
=
pCfg
->
precision
;
pKeepCfg
->
precision
=
pCfg
->
precision
;
switch
(
type
)
{
switch
(
type
)
{
case
TSDB_TYPE_TSMA
:
case
TSDB_TYPE_TSMA
:
ASSERT
(
0
);
ASSERTS
(
0
,
"undefined smaType:%d"
,
(
int32_t
)
type
);
terrno
=
TSDB_CODE_APP_ERROR
;
break
;
break
;
case
TSDB_TYPE_RSMA_L0
:
case
TSDB_TYPE_RSMA_L0
:
SMA_SET_KEEP_CFG
(
pVnode
,
0
);
SMA_SET_KEEP_CFG
(
pVnode
,
0
);
...
@@ -112,19 +115,22 @@ int smaSetKeepCfg(SVnode *pVnode, STsdbKeepCfg *pKeepCfg, STsdbCfg *pCfg, int ty
...
@@ -112,19 +115,22 @@ int smaSetKeepCfg(SVnode *pVnode, STsdbKeepCfg *pKeepCfg, STsdbCfg *pCfg, int ty
SMA_SET_KEEP_CFG
(
pVnode
,
2
);
SMA_SET_KEEP_CFG
(
pVnode
,
2
);
break
;
break
;
default:
default:
ASSERT
(
0
);
ASSERTS
(
0
,
"unknown smaType:%d"
,
(
int32_t
)
type
);
terrno
=
TSDB_CODE_APP_ERROR
;
break
;
break
;
}
}
return
0
;
return
terrno
;
}
}
int32_t
smaOpen
(
SVnode
*
pVnode
,
int8_t
rollback
)
{
int32_t
smaOpen
(
SVnode
*
pVnode
,
int8_t
rollback
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
STsdbCfg
*
pCfg
=
&
pVnode
->
config
.
tsdbCfg
;
STsdbCfg
*
pCfg
=
&
pVnode
->
config
.
tsdbCfg
;
SSma
*
pSma
=
taosMemoryCalloc
(
1
,
sizeof
(
SSma
));
SSma
*
pSma
=
taosMemoryCalloc
(
1
,
sizeof
(
SSma
));
if
(
!
pSma
)
{
if
(
!
pSma
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
code
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
}
}
pVnode
->
pSma
=
pSma
;
pVnode
->
pSma
=
pSma
;
...
@@ -143,21 +149,24 @@ int32_t smaOpen(SVnode *pVnode, int8_t rollback) {
...
@@ -143,21 +149,24 @@ int32_t smaOpen(SVnode *pVnode, int8_t rollback) {
}
else
if
(
i
==
TSDB_RETENTION_L2
)
{
}
else
if
(
i
==
TSDB_RETENTION_L2
)
{
SMA_OPEN_RSMA_IMPL
(
pVnode
,
2
);
SMA_OPEN_RSMA_IMPL
(
pVnode
,
2
);
}
else
{
}
else
{
terrno
=
TSDB_CODE_APP_ERROR
;
code
=
TSDB_CODE_APP_ERROR
;
smaError
(
"vgId:%d, sma open failed since %s, level:%d"
,
TD_VID
(
pVnode
),
t
errstr
(
),
i
);
smaError
(
"vgId:%d, sma open failed since %s, level:%d"
,
TD_VID
(
pVnode
),
t
strerror
(
code
),
i
);
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
}
}
}
}
// restore the rsma
// restore the rsma
if
(
tdRSmaRestore
(
pSma
,
RSMA_RESTORE_REBOOT
,
pVnode
->
state
.
committed
,
rollback
)
<
0
)
{
if
(
tdRSmaRestore
(
pSma
,
RSMA_RESTORE_REBOOT
,
pVnode
->
state
.
committed
,
rollback
)
<
0
)
{
goto
_err
;
code
=
terrno
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
}
}
}
return
0
;
_exit:
_err:
if
(
code
)
{
return
-
1
;
smaError
(
"vgId:%d, %s failed at line %d since %s"
,
TD_VID
(
pVnode
),
__func__
,
lino
,
tstrerror
(
code
));
}
return
code
;
}
}
int32_t
smaClose
(
SSma
*
pSma
)
{
int32_t
smaClose
(
SSma
*
pSma
)
{
...
...
source/dnode/vnode/src/sma/smaRollup.c
浏览文件 @
f24703f8
...
@@ -129,12 +129,17 @@ void *tdFreeRSmaInfo(SSma *pSma, SRSmaInfo *pInfo, bool isDeepFree) {
...
@@ -129,12 +129,17 @@ void *tdFreeRSmaInfo(SSma *pSma, SRSmaInfo *pInfo, bool isDeepFree) {
}
}
static
FORCE_INLINE
int32_t
tdUidStoreInit
(
STbUidStore
**
pStore
)
{
static
FORCE_INLINE
int32_t
tdUidStoreInit
(
STbUidStore
**
pStore
)
{
ASSERT
(
*
pStore
==
NULL
);
if
(
ASSERTS
(
*
pStore
==
NULL
,
"*pStore:%p != NULL"
,
*
pStore
))
{
terrno
=
TSDB_CODE_APP_ERROR
;
return
TSDB_CODE_FAILED
;
}
*
pStore
=
taosMemoryCalloc
(
1
,
sizeof
(
STbUidStore
));
*
pStore
=
taosMemoryCalloc
(
1
,
sizeof
(
STbUidStore
));
if
(
*
pStore
==
NULL
)
{
if
(
*
pStore
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -163,15 +168,14 @@ static int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids,
...
@@ -163,15 +168,14 @@ static int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids,
for
(
int32_t
i
=
0
;
i
<
TSDB_RETENTION_L2
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
TSDB_RETENTION_L2
;
++
i
)
{
if
(
pRSmaInfo
->
taskInfo
[
i
])
{
if
(
pRSmaInfo
->
taskInfo
[
i
])
{
if
((
(
terrno
=
qUpdateQualifiedTableId
(
pRSmaInfo
->
taskInfo
[
i
],
tbUids
,
isAdd
))
<
0
)
)
{
if
((
terrno
=
qUpdateQualifiedTableId
(
pRSmaInfo
->
taskInfo
[
i
],
tbUids
,
isAdd
))
<
0
)
{
tdReleaseRSmaInfo
(
pSma
,
pRSmaInfo
);
tdReleaseRSmaInfo
(
pSma
,
pRSmaInfo
);
smaError
(
"vgId:%d, update tbUidList failed for uid:%"
PRIi64
" level %d since %s"
,
SMA_VID
(
pSma
),
*
suid
,
i
,
smaError
(
"vgId:%d, update tbUidList failed for uid:%"
PRIi64
" level %d since %s"
,
SMA_VID
(
pSma
),
*
suid
,
i
,
terrstr
());
terrstr
());
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
}
else
{
smaDebug
(
"vgId:%d, update tbUidList succeed for qTaskInfo:%p with suid:%"
PRIi64
" uid:%"
PRIi64
" level %d"
,
SMA_VID
(
pSma
),
pRSmaInfo
->
taskInfo
[
0
],
*
suid
,
*
(
int64_t
*
)
taosArrayGet
(
tbUids
,
0
),
i
);
}
}
smaDebug
(
"vgId:%d, update tbUidList succeed for qTaskInfo:%p with suid:%"
PRIi64
" uid:%"
PRIi64
" level %d"
,
SMA_VID
(
pSma
),
pRSmaInfo
->
taskInfo
[
i
],
*
suid
,
*
(
int64_t
*
)
taosArrayGet
(
tbUids
,
0
),
i
);
}
}
}
}
...
@@ -232,8 +236,6 @@ int32_t tdFetchTbUidList(SSma *pSma, STbUidStore **ppStore, tb_uid_t suid, tb_ui
...
@@ -232,8 +236,6 @@ int32_t tdFetchTbUidList(SSma *pSma, STbUidStore **ppStore, tb_uid_t suid, tb_ui
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
ASSERT
(
ppStore
!=
NULL
);
if
(
!
(
*
ppStore
))
{
if
(
!
(
*
ppStore
))
{
if
(
tdUidStoreInit
(
ppStore
)
<
0
)
{
if
(
tdUidStoreInit
(
ppStore
)
<
0
)
{
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
...
@@ -300,12 +302,15 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat
...
@@ -300,12 +302,15 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat
}
}
pItem
->
level
=
idx
==
0
?
TSDB_RETENTION_L1
:
TSDB_RETENTION_L2
;
pItem
->
level
=
idx
==
0
?
TSDB_RETENTION_L1
:
TSDB_RETENTION_L2
;
ASSERT
(
pItem
->
level
>
0
);
if
(
ASSERTS
(
pItem
->
level
>
0
,
"pItem level:%"
PRIi8
" should > 0"
,
pItem
->
level
))
{
terrno
=
TSDB_CODE_APP_ERROR
;
return
TSDB_CODE_FAILED
;
}
SRSmaRef
rsmaRef
=
{.
refId
=
pStat
->
refId
,
.
suid
=
pRSmaInfo
->
suid
};
SRSmaRef
rsmaRef
=
{.
refId
=
pStat
->
refId
,
.
suid
=
pRSmaInfo
->
suid
};
taosHashPut
(
smaMgmt
.
refHash
,
&
pItem
,
POINTER_BYTES
,
&
rsmaRef
,
sizeof
(
rsmaRef
));
taosHashPut
(
smaMgmt
.
refHash
,
&
pItem
,
POINTER_BYTES
,
&
rsmaRef
,
sizeof
(
rsmaRef
));
pItem
->
fetchLevel
=
pItem
->
level
;
taosTmrReset
(
tdRSmaFetchTrigger
,
RSMA_FETCH_INTERVAL
,
pItem
,
smaMgmt
.
tmrHandle
,
&
pItem
->
tmrId
);
taosTmrReset
(
tdRSmaFetchTrigger
,
RSMA_FETCH_INTERVAL
,
pItem
,
smaMgmt
.
tmrHandle
,
&
pItem
->
tmrId
);
smaInfo
(
"vgId:%d, item:%p table:%"
PRIi64
" level:%"
PRIi8
" maxdelay:%"
PRIi64
" watermark:%"
PRIi64
smaInfo
(
"vgId:%d, item:%p table:%"
PRIi64
" level:%"
PRIi8
" maxdelay:%"
PRIi64
" watermark:%"
PRIi64
...
@@ -831,50 +836,51 @@ static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t msgSize,
...
@@ -831,50 +836,51 @@ static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t msgSize,
static
int32_t
tdCloneQTaskInfo
(
SSma
*
pSma
,
qTaskInfo_t
dstTaskInfo
,
qTaskInfo_t
srcTaskInfo
,
SRSmaParam
*
param
,
static
int32_t
tdCloneQTaskInfo
(
SSma
*
pSma
,
qTaskInfo_t
dstTaskInfo
,
qTaskInfo_t
srcTaskInfo
,
SRSmaParam
*
param
,
tb_uid_t
suid
,
int8_t
idx
)
{
tb_uid_t
suid
,
int8_t
idx
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
SVnode
*
pVnode
=
pSma
->
pVnode
;
SVnode
*
pVnode
=
pSma
->
pVnode
;
char
*
pOutput
=
NULL
;
char
*
pOutput
=
NULL
;
int32_t
len
=
0
;
int32_t
len
=
0
;
if
(
!
srcTaskInfo
)
{
if
(
!
srcTaskInfo
)
{
terrno
=
TSDB_CODE_INVALID_PTR
;
code
=
TSDB_CODE_INVALID_PTR
;
smaWarn
(
"vgId:%d, rsma clone, table %"
PRIi64
", no need since srcTaskInfo is NULL"
,
TD_VID
(
pVnode
),
suid
);
smaWarn
(
"vgId:%d, rsma clone, table %"
PRIi64
", no need since srcTaskInfo is NULL"
,
TD_VID
(
pVnode
),
suid
);
return
TSDB_CODE_FAILED
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
}
}
if
((
terrno
=
qSerializeTaskStatus
(
srcTaskInfo
,
&
pOutput
,
&
len
))
<
0
)
{
code
=
qSerializeTaskStatus
(
srcTaskInfo
,
&
pOutput
,
&
len
);
smaError
(
"vgId:%d, rsma clone, table %"
PRIi64
" serialize qTaskInfo failed since %s"
,
TD_VID
(
pVnode
),
suid
,
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
terrstr
());
goto
_err
;
}
SReadHandle
handle
=
{
SReadHandle
handle
=
{
.
meta
=
pVnode
->
pMeta
,
.
meta
=
pVnode
->
pMeta
,
.
vnode
=
pVnode
,
.
vnode
=
pVnode
,
.
initTqReader
=
1
,
.
initTqReader
=
1
,
};
};
ASSERT
(
!
dstTaskInfo
);
if
(
ASSERTS
(
!
dstTaskInfo
,
"dstTaskInfo:%p is not NULL"
,
dstTaskInfo
))
{
code
=
TSDB_CODE_APP_ERROR
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
dstTaskInfo
=
qCreateStreamExecTaskInfo
(
param
->
qmsg
[
idx
],
&
handle
);
dstTaskInfo
=
qCreateStreamExecTaskInfo
(
param
->
qmsg
[
idx
],
&
handle
);
if
(
!
dstTaskInfo
)
{
if
(
!
dstTaskInfo
)
{
terrno
=
TSDB_CODE_RSMA_QTASKINFO_CREATE
;
code
=
TSDB_CODE_RSMA_QTASKINFO_CREATE
;
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
}
}
if
(
qDeserializeTaskStatus
(
dstTaskInfo
,
pOutput
,
len
)
<
0
)
{
code
=
qDeserializeTaskStatus
(
dstTaskInfo
,
pOutput
,
len
);
smaError
(
"vgId:%d, rsma clone, restore rsma task for table:%"
PRIi64
" failed since %s"
,
TD_VID
(
pVnode
),
suid
,
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
terrstr
());
goto
_err
;
}
smaDebug
(
"vgId:%d, rsma clone, restore rsma task for table:%"
PRIi64
" succeed"
,
TD_VID
(
pVnode
),
suid
);
smaDebug
(
"vgId:%d, rsma clone, restore rsma task for table:%"
PRIi64
" succeed"
,
TD_VID
(
pVnode
),
suid
);
_exit:
taosMemoryFreeClear
(
pOutput
);
taosMemoryFreeClear
(
pOutput
);
return
TSDB_CODE_SUCCESS
;
if
(
code
)
{
_err:
tdRSmaQTaskInfoFree
(
dstTaskInfo
,
TD_VID
(
pVnode
),
idx
+
1
);
taosMemoryFreeClear
(
pOutput
);
smaError
(
"vgId:%d, rsma clone, restore rsma task for table:%"
PRIi64
" failed since %s"
,
TD_VID
(
pVnode
),
suid
,
tdRSmaQTaskInfoFree
(
dstTaskInfo
,
TD_VID
(
pVnode
),
idx
+
1
);
terrstr
());
smaError
(
"vgId:%d, rsma clone, restore rsma task for table:%"
PRIi64
" failed since %s"
,
TD_VID
(
pVnode
),
suid
,
}
terrstr
());
return
code
;
return
TSDB_CODE_FAILED
;
}
}
/**
/**
...
@@ -885,43 +891,53 @@ _err:
...
@@ -885,43 +891,53 @@ _err:
* @return int32_t
* @return int32_t
*/
*/
static
int32_t
tdRSmaInfoClone
(
SSma
*
pSma
,
SRSmaInfo
*
pInfo
)
{
static
int32_t
tdRSmaInfoClone
(
SSma
*
pSma
,
SRSmaInfo
*
pInfo
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
SRSmaParam
*
param
=
NULL
;
SRSmaParam
*
param
=
NULL
;
SMetaReader
mr
=
{
0
};
if
(
!
pInfo
)
{
if
(
!
pInfo
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
SMetaReader
mr
=
{
0
};
metaReaderInit
(
&
mr
,
SMA_META
(
pSma
),
0
);
metaReaderInit
(
&
mr
,
SMA_META
(
pSma
),
0
);
smaDebug
(
"vgId:%d, rsma clone qTaskInfo for suid:%"
PRIi64
,
SMA_VID
(
pSma
),
pInfo
->
suid
);
smaDebug
(
"vgId:%d, rsma clone qTaskInfo for suid:%"
PRIi64
,
SMA_VID
(
pSma
),
pInfo
->
suid
);
if
(
metaGetTableEntryByUidCache
(
&
mr
,
pInfo
->
suid
)
<
0
)
{
if
(
metaGetTableEntryByUidCache
(
&
mr
,
pInfo
->
suid
)
<
0
)
{
smaError
(
"vgId:%d, rsma clone, failed to get table meta for %"
PRIi64
" since %s"
,
SMA_VID
(
pSma
),
pInfo
->
suid
,
code
=
terrno
;
terrstr
());
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
goto
_err
;
}
}
ASSERT
(
mr
.
me
.
type
==
TSDB_SUPER_TABLE
);
ASSERT
(
mr
.
me
.
uid
==
pInfo
->
suid
);
if
(
mr
.
me
.
type
!=
TSDB_SUPER_TABLE
)
{
code
=
TSDB_CODE_RSMA_INVALID_SCHEMA
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
if
(
mr
.
me
.
uid
!=
pInfo
->
suid
)
{
code
=
TSDB_CODE_RSMA_INVALID_SCHEMA
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
if
(
TABLE_IS_ROLLUP
(
mr
.
me
.
flags
))
{
if
(
TABLE_IS_ROLLUP
(
mr
.
me
.
flags
))
{
param
=
&
mr
.
me
.
stbEntry
.
rsmaParam
;
param
=
&
mr
.
me
.
stbEntry
.
rsmaParam
;
for
(
int32_t
i
=
0
;
i
<
TSDB_RETENTION_L2
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
TSDB_RETENTION_L2
;
++
i
)
{
if
(
!
pInfo
->
iTaskInfo
[
i
])
{
if
(
!
pInfo
->
iTaskInfo
[
i
])
{
continue
;
continue
;
}
}
if
(
tdCloneQTaskInfo
(
pSma
,
pInfo
->
taskInfo
[
i
],
pInfo
->
iTaskInfo
[
i
],
param
,
pInfo
->
suid
,
i
)
<
0
)
{
code
=
tdCloneQTaskInfo
(
pSma
,
pInfo
->
taskInfo
[
i
],
pInfo
->
iTaskInfo
[
i
],
param
,
pInfo
->
suid
,
i
);
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
}
}
smaDebug
(
"vgId:%d, rsma clone env success for %"
PRIi64
,
SMA_VID
(
pSma
),
pInfo
->
suid
);
smaDebug
(
"vgId:%d, rsma clone env success for %"
PRIi64
,
SMA_VID
(
pSma
),
pInfo
->
suid
);
}
else
{
}
else
{
terrno
=
TSDB_CODE_RSMA_INVALID_SCHEMA
;
code
=
TSDB_CODE_RSMA_INVALID_SCHEMA
;
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
}
}
_exit:
if
(
code
)
{
smaError
(
"vgId:%d, %s failed at line %d since %s, suid:%"
PRIi64
", flags:%"
PRIi8
",type:%"
PRIi8
", uid:%"
PRIi64
,
SMA_VID
(
pSma
),
__func__
,
lino
,
tstrerror
(
code
),
pInfo
->
suid
,
mr
.
me
.
flags
,
mr
.
me
.
type
,
mr
.
me
.
uid
);
}
metaReaderClear
(
&
mr
);
metaReaderClear
(
&
mr
);
return
TSDB_CODE_SUCCESS
;
return
code
;
_err:
metaReaderClear
(
&
mr
);
smaError
(
"vgId:%d, rsma clone env failed for %"
PRIi64
" since %s"
,
SMA_VID
(
pSma
),
pInfo
->
suid
,
terrstr
());
return
TSDB_CODE_FAILED
;
}
}
/**
/**
...
@@ -932,10 +948,14 @@ _err:
...
@@ -932,10 +948,14 @@ _err:
* @return SRSmaInfo*
* @return SRSmaInfo*
*/
*/
static
SRSmaInfo
*
tdAcquireRSmaInfoBySuid
(
SSma
*
pSma
,
int64_t
suid
)
{
static
SRSmaInfo
*
tdAcquireRSmaInfoBySuid
(
SSma
*
pSma
,
int64_t
suid
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
SSmaEnv
*
pEnv
=
SMA_RSMA_ENV
(
pSma
);
SSmaEnv
*
pEnv
=
SMA_RSMA_ENV
(
pSma
);
SRSmaStat
*
pStat
=
NULL
;
SRSmaStat
*
pStat
=
NULL
;
SRSmaInfo
*
pRSmaInfo
=
NULL
;
SRSmaInfo
*
pRSmaInfo
=
NULL
;
terrno
=
0
;
if
(
!
pEnv
)
{
if
(
!
pEnv
)
{
terrno
=
TSDB_CODE_RSMA_INVALID_ENV
;
terrno
=
TSDB_CODE_RSMA_INVALID_ENV
;
return
NULL
;
return
NULL
;
...
@@ -955,14 +975,17 @@ static SRSmaInfo *tdAcquireRSmaInfoBySuid(SSma *pSma, int64_t suid) {
...
@@ -955,14 +975,17 @@ static SRSmaInfo *tdAcquireRSmaInfoBySuid(SSma *pSma, int64_t suid) {
return
NULL
;
return
NULL
;
}
}
if
(
!
pRSmaInfo
->
taskInfo
[
0
])
{
if
(
!
pRSmaInfo
->
taskInfo
[
0
])
{
if
(
tdRSmaInfoClone
(
pSma
,
pRSmaInfo
)
<
0
)
{
if
(
(
terrno
=
tdRSmaInfoClone
(
pSma
,
pRSmaInfo
)
)
<
0
)
{
taosRUnLockLatch
(
SMA_ENV_LOCK
(
pEnv
));
taosRUnLockLatch
(
SMA_ENV_LOCK
(
pEnv
));
return
NULL
;
return
NULL
;
}
}
}
}
tdRefRSmaInfo
(
pSma
,
pRSmaInfo
);
tdRefRSmaInfo
(
pSma
,
pRSmaInfo
);
taosRUnLockLatch
(
SMA_ENV_LOCK
(
pEnv
));
taosRUnLockLatch
(
SMA_ENV_LOCK
(
pEnv
));
ASSERT
(
pRSmaInfo
->
suid
==
suid
);
if
(
ASSERTS
(
pRSmaInfo
->
suid
==
suid
,
"suid:%"
PRIi64
" != %"
PRIi64
,
pRSmaInfo
->
suid
,
suid
))
{
terrno
=
TSDB_CODE_APP_ERROR
;
return
NULL
;
}
return
pRSmaInfo
;
return
pRSmaInfo
;
}
}
taosRUnLockLatch
(
SMA_ENV_LOCK
(
pEnv
));
taosRUnLockLatch
(
SMA_ENV_LOCK
(
pEnv
));
...
@@ -1010,7 +1033,11 @@ static int32_t tdExecuteRSmaAsync(SSma *pSma, int64_t version, const void *pMsg,
...
@@ -1010,7 +1033,11 @@ static int32_t tdExecuteRSmaAsync(SSma *pSma, int64_t version, const void *pMsg,
}
}
}
}
}
else
{
}
else
{
ASSERT
(
0
);
terrno
=
TSDB_CODE_APP_ERROR
;
tdReleaseRSmaInfo
(
pSma
,
pRSmaInfo
);
smaError
(
"vgId:%d, execute rsma, failed for suid:%"
PRIu64
" since %s, type:%d"
,
SMA_VID
(
pSma
),
suid
,
tstrerror
(
terrno
),
inputType
);
return
TSDB_CODE_FAILED
;
}
}
tdReleaseRSmaInfo
(
pSma
,
pRSmaInfo
);
tdReleaseRSmaInfo
(
pSma
,
pRSmaInfo
);
...
@@ -1063,19 +1090,22 @@ _err:
...
@@ -1063,19 +1090,22 @@ _err:
* @return int32_t
* @return int32_t
*/
*/
static
int32_t
tdRSmaRestoreQTaskInfoInit
(
SSma
*
pSma
,
int64_t
*
nTables
)
{
static
int32_t
tdRSmaRestoreQTaskInfoInit
(
SSma
*
pSma
,
int64_t
*
nTables
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
SVnode
*
pVnode
=
pSma
->
pVnode
;
SVnode
*
pVnode
=
pSma
->
pVnode
;
SArray
*
suidList
=
NULL
;
SArray
*
suidList
=
NULL
;
STbUidStore
uidStore
=
{
0
};
STbUidStore
uidStore
=
{
0
};
SMetaReader
mr
=
{
0
};
SMetaReader
mr
=
{
0
};
tb_uid_t
suid
=
0
;
if
(
!
(
suidList
=
taosArrayInit
(
1
,
sizeof
(
tb_uid_t
))))
{
if
(
!
(
suidList
=
taosArrayInit
(
1
,
sizeof
(
tb_uid_t
))))
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
}
}
if
(
vnodeGetStbIdList
(
pSma
->
pVnode
,
0
,
suidList
)
<
0
)
{
if
(
vnodeGetStbIdList
(
pSma
->
pVnode
,
0
,
suidList
)
<
0
)
{
smaError
(
"vgId:%d, failed to restore rsma env since get stb id list error: %s"
,
TD_VID
(
pVnode
),
terrstr
())
;
code
=
terrno
;
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
}
}
int64_t
arrSize
=
taosArrayGetSize
(
suidList
);
int64_t
arrSize
=
taosArrayGetSize
(
suidList
);
...
@@ -1092,19 +1122,26 @@ static int32_t tdRSmaRestoreQTaskInfoInit(SSma *pSma, int64_t *nTables) {
...
@@ -1092,19 +1122,26 @@ static int32_t tdRSmaRestoreQTaskInfoInit(SSma *pSma, int64_t *nTables) {
int64_t
nRsmaTables
=
0
;
int64_t
nRsmaTables
=
0
;
metaReaderInit
(
&
mr
,
SMA_META
(
pSma
),
0
);
metaReaderInit
(
&
mr
,
SMA_META
(
pSma
),
0
);
if
(
!
(
uidStore
.
tbUids
=
taosArrayInit
(
1024
,
sizeof
(
tb_uid_t
))))
{
if
(
!
(
uidStore
.
tbUids
=
taosArrayInit
(
1024
,
sizeof
(
tb_uid_t
))))
{
goto
_err
;
code
=
TSDB_CODE_OUT_OF_MEMORY
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
}
for
(
int64_t
i
=
0
;
i
<
arrSize
;
++
i
)
{
for
(
int64_t
i
=
0
;
i
<
arrSize
;
++
i
)
{
tb_uid_t
suid
=
*
(
tb_uid_t
*
)
taosArrayGet
(
suidList
,
i
);
suid
=
*
(
tb_uid_t
*
)
taosArrayGet
(
suidList
,
i
);
smaDebug
(
"vgId:%d, rsma restore, suid is %"
PRIi64
,
TD_VID
(
pVnode
),
suid
);
smaDebug
(
"vgId:%d, rsma restore, suid is %"
PRIi64
,
TD_VID
(
pVnode
),
suid
);
if
(
metaGetTableEntryByUidCache
(
&
mr
,
suid
)
<
0
)
{
if
(
metaGetTableEntryByUidCache
(
&
mr
,
suid
)
<
0
)
{
smaError
(
"vgId:%d, rsma restore, failed to get table meta for %"
PRIi64
" since %s"
,
TD_VID
(
pVnode
),
suid
,
code
=
terrno
;
terrstr
());
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
goto
_err
;
}
}
tDecoderClear
(
&
mr
.
coder
);
tDecoderClear
(
&
mr
.
coder
);
ASSERT
(
mr
.
me
.
type
==
TSDB_SUPER_TABLE
);
if
(
mr
.
me
.
type
!=
TSDB_SUPER_TABLE
)
{
ASSERT
(
mr
.
me
.
uid
==
suid
);
code
=
TSDB_CODE_RSMA_INVALID_SCHEMA
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
if
(
mr
.
me
.
uid
!=
suid
)
{
code
=
TSDB_CODE_RSMA_INVALID_SCHEMA
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
if
(
TABLE_IS_ROLLUP
(
mr
.
me
.
flags
))
{
if
(
TABLE_IS_ROLLUP
(
mr
.
me
.
flags
))
{
++
nRsmaTables
;
++
nRsmaTables
;
SRSmaParam
*
param
=
&
mr
.
me
.
stbEntry
.
rsmaParam
;
SRSmaParam
*
param
=
&
mr
.
me
.
stbEntry
.
rsmaParam
;
...
@@ -1114,22 +1151,20 @@ static int32_t tdRSmaRestoreQTaskInfoInit(SSma *pSma, int64_t *nTables) {
...
@@ -1114,22 +1151,20 @@ static int32_t tdRSmaRestoreQTaskInfoInit(SSma *pSma, int64_t *nTables) {
TD_VID
(
pVnode
),
suid
,
i
,
param
->
maxdelay
[
i
],
param
->
watermark
[
i
],
param
->
qmsgLen
[
i
]);
TD_VID
(
pVnode
),
suid
,
i
,
param
->
maxdelay
[
i
],
param
->
watermark
[
i
],
param
->
qmsgLen
[
i
]);
}
}
if
(
tdRSmaProcessCreateImpl
(
pSma
,
&
mr
.
me
.
stbEntry
.
rsmaParam
,
suid
,
mr
.
me
.
name
)
<
0
)
{
if
(
tdRSmaProcessCreateImpl
(
pSma
,
&
mr
.
me
.
stbEntry
.
rsmaParam
,
suid
,
mr
.
me
.
name
)
<
0
)
{
smaError
(
"vgId:%d, rsma restore env failed for %"
PRIi64
" since %s"
,
TD_VID
(
pVnode
),
suid
,
terrstr
())
;
code
=
terrno
;
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
}
}
// reload all ctbUids for suid
// reload all ctbUids for suid
uidStore
.
suid
=
suid
;
uidStore
.
suid
=
suid
;
if
(
vnodeGetCtbIdList
(
pVnode
,
suid
,
uidStore
.
tbUids
)
<
0
)
{
if
(
vnodeGetCtbIdList
(
pVnode
,
suid
,
uidStore
.
tbUids
)
<
0
)
{
smaError
(
"vgId:%d, rsma restore, get ctb idlist failed for %"
PRIi64
" since %s"
,
TD_VID
(
pVnode
),
suid
,
code
=
terrno
;
terrstr
());
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
goto
_err
;
}
}
if
(
tdUpdateTbUidList
(
pVnode
->
pSma
,
&
uidStore
,
true
)
<
0
)
{
if
(
tdUpdateTbUidList
(
pVnode
->
pSma
,
&
uidStore
,
true
)
<
0
)
{
smaError
(
"vgId:%d, rsma restore, update tb uid list failed for %"
PRIi64
" since %s"
,
TD_VID
(
pVnode
),
suid
,
code
=
terrno
;
terrstr
());
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
goto
_err
;
}
}
taosArrayClear
(
uidStore
.
tbUids
);
taosArrayClear
(
uidStore
.
tbUids
);
...
@@ -1138,21 +1173,18 @@ static int32_t tdRSmaRestoreQTaskInfoInit(SSma *pSma, int64_t *nTables) {
...
@@ -1138,21 +1173,18 @@ static int32_t tdRSmaRestoreQTaskInfoInit(SSma *pSma, int64_t *nTables) {
}
}
}
}
metaReaderClear
(
&
mr
);
taosArrayDestroy
(
suidList
);
tdUidStoreDestory
(
&
uidStore
);
if
(
nTables
)
{
if
(
nTables
)
{
*
nTables
=
nRsmaTables
;
*
nTables
=
nRsmaTables
;
}
}
_exit:
return
TSDB_CODE_SUCCESS
;
if
(
code
)
{
_err:
smaError
(
"vgId:%d, %s failed at line %d since %s, suid:%"
PRIi64
", type:%"
PRIi8
", uid:%"
PRIi64
,
TD_VID
(
pVnode
),
__func__
,
lino
,
tstrerror
(
code
),
suid
,
mr
.
me
.
type
,
mr
.
me
.
uid
);
}
metaReaderClear
(
&
mr
);
metaReaderClear
(
&
mr
);
taosArrayDestroy
(
suidList
);
taosArrayDestroy
(
suidList
);
tdUidStoreDestory
(
&
uidStore
);
tdUidStoreDestory
(
&
uidStore
);
return
code
;
return
TSDB_CODE_FAILED
;
}
}
/**
/**
...
@@ -1254,7 +1286,6 @@ int32_t tdRSmaPersistExecImpl(SRSmaStat *pRSmaStat, SHashObj *pInfoHash) {
...
@@ -1254,7 +1286,6 @@ int32_t tdRSmaPersistExecImpl(SRSmaStat *pRSmaStat, SHashObj *pInfoHash) {
code
=
TAOS_SYSTEM_ERROR
(
errno
);
code
=
TAOS_SYSTEM_ERROR
(
errno
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
}
ASSERT
(
size
>
0
);
int64_t
offset
=
0
;
int64_t
offset
=
0
;
if
(
taosFSendFile
(
pOutFD
,
pInFD
,
&
offset
,
size
)
<
0
)
{
if
(
taosFSendFile
(
pOutFD
,
pInFD
,
&
offset
,
size
)
<
0
)
{
...
@@ -1374,10 +1405,11 @@ static void tdRSmaFetchTrigger(void *param, void *tmrId) {
...
@@ -1374,10 +1405,11 @@ static void tdRSmaFetchTrigger(void *param, void *tmrId) {
// async process
// async process
pItem
->
fetchLevel
=
pItem
->
level
;
pItem
->
fetchLevel
=
pItem
->
level
;
#if 0
#if 0
// debugging codes
SRSmaInfo *qInfo = tdAcquireRSmaInfoBySuid(pSma, pRSmaInfo->suid);
SRSmaInfo *qInfo = tdAcquireRSmaInfoBySuid(pSma, pRSmaInfo->suid);
SRSmaInfoItem *qItem = RSMA_INFO_ITEM(qInfo, pItem->level - 1);
SRSmaInfoItem *qItem = RSMA_INFO_ITEM(qInfo, pItem->level - 1);
ASSERT
(qItem->level == pItem->level);
make sure
(qItem->level == pItem->level);
ASSERT
(qItem->fetchLevel == pItem->fetchLevel);
make sure
(qItem->fetchLevel == pItem->fetchLevel);
#endif
#endif
if
(
atomic_load_8
(
&
pRSmaInfo
->
assigned
)
==
0
)
{
if
(
atomic_load_8
(
&
pRSmaInfo
->
assigned
)
==
0
)
{
tsem_post
(
&
(
pStat
->
notEmpty
));
tsem_post
(
&
(
pStat
->
notEmpty
));
...
@@ -1524,6 +1556,8 @@ _err:
...
@@ -1524,6 +1556,8 @@ _err:
*/
*/
int32_t
tdRSmaProcessExecImpl
(
SSma
*
pSma
,
ERsmaExecType
type
)
{
int32_t
tdRSmaProcessExecImpl
(
SSma
*
pSma
,
ERsmaExecType
type
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
SVnode
*
pVnode
=
pSma
->
pVnode
;
SVnode
*
pVnode
=
pSma
->
pVnode
;
SSmaEnv
*
pEnv
=
SMA_RSMA_ENV
(
pSma
);
SSmaEnv
*
pEnv
=
SMA_RSMA_ENV
(
pSma
);
SRSmaStat
*
pRSmaStat
=
(
SRSmaStat
*
)
SMA_ENV_STAT
(
pEnv
);
SRSmaStat
*
pRSmaStat
=
(
SRSmaStat
*
)
SMA_ENV_STAT
(
pEnv
);
...
@@ -1532,14 +1566,14 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
...
@@ -1532,14 +1566,14 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
bool
isFetchAll
=
false
;
bool
isFetchAll
=
false
;
if
(
!
pRSmaStat
||
!
(
infoHash
=
RSMA_INFO_HASH
(
pRSmaStat
)))
{
if
(
!
pRSmaStat
||
!
(
infoHash
=
RSMA_INFO_HASH
(
pRSmaStat
)))
{
terrno
=
TSDB_CODE_RSMA_INVALID_STAT
;
code
=
TSDB_CODE_RSMA_INVALID_STAT
;
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
}
}
if
(
!
(
pSubmitArr
=
if
(
!
(
pSubmitArr
=
taosArrayInit
(
TMIN
(
RSMA_SUBMIT_BATCH_SIZE
,
atomic_load_64
(
&
pRSmaStat
->
nBufItems
)),
sizeof
(
SPackedData
))))
{
taosArrayInit
(
TMIN
(
RSMA_SUBMIT_BATCH_SIZE
,
atomic_load_64
(
&
pRSmaStat
->
nBufItems
)),
sizeof
(
SPackedData
))))
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
}
}
while
(
true
)
{
while
(
true
)
{
...
@@ -1570,7 +1604,11 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
...
@@ -1570,7 +1604,11 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
if
(
oldStat
==
0
||
if
(
oldStat
==
0
||
((
oldStat
==
2
)
&&
atomic_load_8
(
RSMA_TRIGGER_STAT
(
pRSmaStat
))
<
TASK_TRIGGER_STAT_PAUSED
))
{
((
oldStat
==
2
)
&&
atomic_load_8
(
RSMA_TRIGGER_STAT
(
pRSmaStat
))
<
TASK_TRIGGER_STAT_PAUSED
))
{
int32_t
oldVal
=
atomic_fetch_add_32
(
&
pRSmaStat
->
nFetchAll
,
1
);
int32_t
oldVal
=
atomic_fetch_add_32
(
&
pRSmaStat
->
nFetchAll
,
1
);
ASSERT
(
oldVal
>=
0
);
if
(
ASSERTS
(
oldVal
>=
0
,
"oldVal of nFetchAll: %d < 0"
,
oldVal
))
{
code
=
TSDB_CODE_APP_ERROR
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
int8_t
curStat
=
atomic_load_8
(
RSMA_COMMIT_STAT
(
pRSmaStat
));
int8_t
curStat
=
atomic_load_8
(
RSMA_COMMIT_STAT
(
pRSmaStat
));
if
(
curStat
==
1
)
{
if
(
curStat
==
1
)
{
...
@@ -1600,7 +1638,9 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
...
@@ -1600,7 +1638,9 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
}
}
}
}
}
else
{
}
else
{
ASSERT
(
0
);
ASSERTS
(
0
,
"unknown rsma exec type:%d"
,
(
int32_t
)
type
);
code
=
TSDB_CODE_APP_ERROR
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
}
if
(
atomic_load_64
(
&
pRSmaStat
->
nBufItems
)
<=
0
)
{
if
(
atomic_load_64
(
&
pRSmaStat
->
nBufItems
)
<=
0
)
{
...
@@ -1619,10 +1659,10 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
...
@@ -1619,10 +1659,10 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
}
// end of while(true)
}
// end of while(true)
_end:
_exit:
taosArrayDestroy
(
pSubmitArr
);
return
TSDB_CODE_SUCCESS
;
_err:
taosArrayDestroy
(
pSubmitArr
);
taosArrayDestroy
(
pSubmitArr
);
return
TSDB_CODE_FAILED
;
if
(
code
)
{
smaError
(
"vgId:%d, %s failed at line %d since %s"
,
TD_VID
(
pVnode
),
__func__
,
lino
,
tstrerror
(
code
));
}
return
code
;
}
}
source/libs/tfs/src/tfs.c
浏览文件 @
f24703f8
...
@@ -284,7 +284,9 @@ int32_t tfsMkdir(STfs *pTfs, const char *rname) {
...
@@ -284,7 +284,9 @@ int32_t tfsMkdir(STfs *pTfs, const char *rname) {
}
}
int32_t
tfsRmdir
(
STfs
*
pTfs
,
const
char
*
rname
)
{
int32_t
tfsRmdir
(
STfs
*
pTfs
,
const
char
*
rname
)
{
ASSERT
(
rname
[
0
]
!=
0
);
if
(
rname
[
0
]
==
0
)
{
return
0
;
}
char
aname
[
TMPNAME_LEN
]
=
"
\0
"
;
char
aname
[
TMPNAME_LEN
]
=
"
\0
"
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录