Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7facf64e
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
7facf64e
编写于
12月 01, 2022
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: optimize ctg code
上级
4b11f358
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
173 addition
and
28 deletion
+173
-28
source/libs/catalog/inc/catalogInt.h
source/libs/catalog/inc/catalogInt.h
+2
-0
source/libs/catalog/src/catalog.c
source/libs/catalog/src/catalog.c
+1
-1
source/libs/catalog/src/ctgCache.c
source/libs/catalog/src/ctgCache.c
+51
-8
source/libs/catalog/src/ctgUtil.c
source/libs/catalog/src/ctgUtil.c
+119
-19
未找到文件。
source/libs/catalog/inc/catalogInt.h
浏览文件 @
7facf64e
...
...
@@ -764,6 +764,8 @@ void ctgFreeJob(void* job);
void
ctgFreeHandleImpl
(
SCatalog
*
pCtg
);
void
ctgFreeVgInfo
(
SDBVgInfo
*
vgInfo
);
int32_t
ctgGetVgInfoFromHashValue
(
SCatalog
*
pCtg
,
SDBVgInfo
*
dbInfo
,
const
SName
*
pTableName
,
SVgroupInfo
*
pVgroup
);
int32_t
ctgGetVgInfoFromHashValue2
(
SCatalog
*
pCtg
,
SDBVgInfo
*
dbInfo
,
const
SName
*
pTableName
,
SVgroupInfo
*
pVgroup
);
int32_t
ctgGetVgInfosFromHashValue
(
SCatalog
*
pCtg
,
SCtgTaskReq
*
tReq
,
SDBVgInfo
*
dbInfo
,
SCtgTbHashsCtx
*
pCtx
,
char
*
dbFName
,
SArray
*
pNames
,
bool
update
);
void
ctgResetTbMetaTask
(
SCtgTask
*
pTask
);
...
...
source/libs/catalog/src/catalog.c
浏览文件 @
7facf64e
...
...
@@ -536,7 +536,7 @@ int32_t ctgGetTbHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName*
return
TSDB_CODE_SUCCESS
;
}
CTG_ERR_JRET
(
ctgGetVgInfoFromHashValue
(
pCtg
,
vgInfo
?
vgInfo
:
dbCache
->
vgCache
.
vgInfo
,
pTableName
,
pVgroup
));
CTG_ERR_JRET
(
ctgGetVgInfoFromHashValue
2
(
pCtg
,
vgInfo
?
vgInfo
:
dbCache
->
vgCache
.
vgInfo
,
pTableName
,
pVgroup
));
_return:
...
...
source/libs/catalog/src/ctgCache.c
浏览文件 @
7facf64e
...
...
@@ -277,6 +277,49 @@ _return:
return
TSDB_CODE_SUCCESS
;
}
int32_t
ctgAcquireStbMetaFromCache2
(
SCtgDBCache
*
dbCache
,
SCatalog
*
pCtg
,
char
*
dbFName
,
uint64_t
suid
,
SCtgTbCache
**
pTb
)
{
SCtgTbCache
*
pCache
=
NULL
;
char
*
stName
=
taosHashAcquire
(
dbCache
->
stbCache
,
&
suid
,
sizeof
(
suid
));
if
(
NULL
==
stName
)
{
ctgDebug
(
"stb 0x%"
PRIx64
" not in cache, dbFName:%s"
,
suid
,
dbFName
);
goto
_return
;
}
pCache
=
taosHashAcquire
(
dbCache
->
tbCache
,
stName
,
strlen
(
stName
));
if
(
NULL
==
pCache
)
{
ctgDebug
(
"stb 0x%"
PRIx64
" name %s not in cache, dbFName:%s"
,
suid
,
stName
,
dbFName
);
taosHashRelease
(
dbCache
->
stbCache
,
stName
);
goto
_return
;
}
taosHashRelease
(
dbCache
->
stbCache
,
stName
);
CTG_LOCK
(
CTG_READ
,
&
pCache
->
metaLock
);
if
(
NULL
==
pCache
->
pMeta
)
{
ctgDebug
(
"stb 0x%"
PRIx64
" meta not in cache, dbFName:%s"
,
suid
,
dbFName
);
goto
_return
;
}
*
pTb
=
pCache
;
ctgDebug
(
"stb 0x%"
PRIx64
" meta got in cache, dbFName:%s"
,
suid
,
dbFName
);
CTG_CACHE_STAT_INC
(
numOfMetaHit
,
1
);
return
TSDB_CODE_SUCCESS
;
_return:
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
pCache
);
CTG_CACHE_STAT_INC
(
numOfMetaMiss
,
1
);
*
pTb
=
NULL
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
ctgAcquireTbIndexFromCache
(
SCatalog
*
pCtg
,
char
*
dbFName
,
char
*
tbName
,
SCtgDBCache
**
pDb
,
SCtgTbCache
**
pTb
)
{
SCtgDBCache
*
dbCache
=
NULL
;
SCtgTbCache
*
pCache
=
NULL
;
...
...
@@ -384,17 +427,17 @@ int32_t ctgReadTbMetaFromCache(SCatalog *pCtg, SCtgTbMetaCtx *ctx, STableMeta **
memcpy
(
*
pTableMeta
,
tbMeta
,
metaSize
);
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
tbCache
);
//ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
if
(
tbCache
)
{
CTG_UNLOCK
(
CTG_READ
,
&
tbCache
->
metaLock
);
taosHashRelease
(
dbCache
->
tbCache
,
tbCache
);
}
ctgDebug
(
"Got ctb %s meta from cache, will continue to get its stb meta, type:%d, dbFName:%s"
,
ctx
->
pName
->
tname
,
ctx
->
tbInfo
.
tbType
,
dbFName
);
ctgAcquireStbMetaFromCache
(
pCtg
,
dbFName
,
ctx
->
tbInfo
.
suid
,
&
dbCache
,
&
tbCache
);
if
(
NULL
==
tbCache
)
{
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
tbCache
);
taosMemoryFreeClear
(
*
pTableMeta
);
ctgDebug
(
"stb 0x%"
PRIx64
" meta not in cache"
,
ctx
->
tbInfo
.
suid
);
return
TSDB_CODE_SUCCESS
;
}
ctgAcquireStbMetaFromCache2
(
dbCache
,
pCtg
,
dbFName
,
ctx
->
tbInfo
.
suid
,
&
tbCache
);
STableMeta
*
stbMeta
=
tbCache
->
pMeta
;
if
(
stbMeta
->
suid
!=
ctx
->
tbInfo
.
suid
)
{
...
...
source/libs/catalog/src/ctgUtil.c
浏览文件 @
7facf64e
...
...
@@ -837,6 +837,57 @@ _return:
CTG_RET
(
code
);
}
int
ctgVgInfoComp2
(
const
void
*
lp
,
const
void
*
rp
)
{
SVgroupInfo
*
pLeft
=
(
SVgroupInfo
*
)
lp
;
SVgroupInfo
*
pRight
=
(
SVgroupInfo
*
)
rp
;
if
(
pLeft
->
hashBegin
<
pRight
->
hashBegin
)
{
return
-
1
;
}
else
if
(
pLeft
->
hashBegin
>
pRight
->
hashBegin
)
{
return
1
;
}
return
0
;
}
int32_t
ctgHashValueComp
(
void
const
*
lp
,
void
const
*
rp
)
{
uint32_t
*
key
=
(
uint32_t
*
)
lp
;
SVgroupInfo
*
pVg
=
*
(
SVgroupInfo
**
)
rp
;
if
(
*
key
<
pVg
->
hashBegin
)
{
return
-
1
;
}
else
if
(
*
key
>
pVg
->
hashEnd
)
{
return
1
;
}
return
0
;
}
int
ctgVgInfoComp
(
const
void
*
lp
,
const
void
*
rp
)
{
SVgroupInfo
*
pLeft
=
*
(
SVgroupInfo
**
)
lp
;
SVgroupInfo
*
pRight
=
*
(
SVgroupInfo
**
)
rp
;
if
(
pLeft
->
hashBegin
<
pRight
->
hashBegin
)
{
return
-
1
;
}
else
if
(
pLeft
->
hashBegin
>
pRight
->
hashBegin
)
{
return
1
;
}
return
0
;
}
int32_t
ctgHashValueComp2
(
void
const
*
lp
,
void
const
*
rp
)
{
uint32_t
*
key
=
(
uint32_t
*
)
lp
;
SVgroupInfo
*
pVg
=
(
SVgroupInfo
*
)
rp
;
if
(
*
key
<
pVg
->
hashBegin
)
{
return
-
1
;
}
else
if
(
*
key
>
pVg
->
hashEnd
)
{
return
1
;
}
return
0
;
}
int32_t
ctgGetVgInfoFromHashValue
(
SCatalog
*
pCtg
,
SDBVgInfo
*
dbInfo
,
const
SName
*
pTableName
,
SVgroupInfo
*
pVgroup
)
{
int32_t
code
=
0
;
...
...
@@ -869,7 +920,7 @@ int32_t ctgGetVgInfoFromHashValue(SCatalog* pCtg, SDBVgInfo* dbInfo, const SName
}
if
(
NULL
==
vgInfo
)
{
ctgError
(
"no hash range found for hash value [%u], db:%s, numOfVgId:%d"
,
hashValue
,
db
,
ctgError
(
"
0
no hash range found for hash value [%u], db:%s, numOfVgId:%d"
,
hashValue
,
db
,
taosHashGetSize
(
dbInfo
->
vgHash
));
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
}
...
...
@@ -883,29 +934,78 @@ int32_t ctgGetVgInfoFromHashValue(SCatalog* pCtg, SDBVgInfo* dbInfo, const SName
CTG_RET
(
code
);
}
int32_t
ctgHashValueComp
(
void
const
*
lp
,
void
const
*
rp
)
{
uint32_t
*
key
=
(
uint32_t
*
)
lp
;
SVgroupInfo
*
pVg
=
*
(
SVgroupInfo
**
)
rp
;
if
(
*
key
<
pVg
->
hashBegin
)
{
return
-
1
;
}
else
if
(
*
key
>
pVg
->
hashEnd
)
{
return
1
;
int32_t
ctgGetVgInfoFromHashValue2
(
SCatalog
*
pCtg
,
SDBVgInfo
*
dbInfo
,
const
SName
*
pTableName
,
SVgroupInfo
*
pVgroup
)
{
int32_t
code
=
0
;
int32_t
vgNum
=
taosHashGetSize
(
dbInfo
->
vgHash
);
char
db
[
TSDB_DB_FNAME_LEN
]
=
{
0
};
tNameGetFullDbName
(
pTableName
,
db
);
if
(
vgNum
<=
0
)
{
ctgError
(
"db vgroup cache invalid, db:%s, vgroup number:%d"
,
db
,
vgNum
);
CTG_ERR_RET
(
TSDB_CODE_TSC_DB_NOT_SELECTED
);
}
return
0
;
}
SVgroupInfo
*
vgInfo
=
NULL
;
char
tbFullName
[
TSDB_TABLE_FNAME_LEN
];
tNameExtractFullName
(
pTableName
,
tbFullName
);
int
ctgVgInfoComp
(
const
void
*
lp
,
const
void
*
rp
)
{
SVgroupInfo
*
pLeft
=
*
(
SVgroupInfo
**
)
lp
;
SVgroupInfo
*
pRight
=
*
(
SVgroupInfo
**
)
rp
;
if
(
pLeft
->
hashBegin
<
pRight
->
hashBegin
)
{
return
-
1
;
}
else
if
(
pLeft
->
hashBegin
>
pRight
->
hashBegin
)
{
return
1
;
uint32_t
hashValue
=
taosGetTbHashVal
(
tbFullName
,
(
uint32_t
)
strlen
(
tbFullName
),
dbInfo
->
hashMethod
,
dbInfo
->
hashPrefix
,
dbInfo
->
hashSuffix
);
static
SArray
*
pVgList
=
NULL
;
static
bool
created
=
false
;
if
(
!
created
)
{
ctgDebug
(
"create vg array, %d"
,
taosHashGetSize
(
dbInfo
->
vgHash
));
pVgList
=
taosArrayInit
(
100
,
sizeof
(
SVgroupInfo
));
void
*
pIter
=
taosHashIterate
(
dbInfo
->
vgHash
,
NULL
);
while
(
pIter
)
{
taosArrayPush
(
pVgList
,
pIter
);
pIter
=
taosHashIterate
(
dbInfo
->
vgHash
,
pIter
);
}
taosArraySort
(
pVgList
,
ctgVgInfoComp2
);
created
=
true
;
}
return
0
;
vgInfo
=
taosArraySearch
(
pVgList
,
&
hashValue
,
ctgHashValueComp2
,
TD_EQ
);
if
(
NULL
==
vgInfo
)
{
void
*
pIter
=
taosHashIterate
(
dbInfo
->
vgHash
,
NULL
);
while
(
pIter
)
{
vgInfo
=
pIter
;
if
(
hashValue
>=
vgInfo
->
hashBegin
&&
hashValue
<=
vgInfo
->
hashEnd
)
{
taosHashCancelIterate
(
dbInfo
->
vgHash
,
pIter
);
break
;
}
pIter
=
taosHashIterate
(
dbInfo
->
vgHash
,
pIter
);
vgInfo
=
NULL
;
}
if
(
vgInfo
)
{
taosArrayDestroy
(
pVgList
);
created
=
false
;
ctgDebug
(
"need to re-create vg array, %d"
,
taosHashGetSize
(
dbInfo
->
vgHash
));
}
}
if
(
NULL
==
vgInfo
)
{
ctgError
(
"1no hash range found for hash value [%u], db:%s, numOfVgId:%d"
,
hashValue
,
db
,
taosHashGetSize
(
dbInfo
->
vgHash
));
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
}
*
pVgroup
=
*
vgInfo
;
ctgDebug
(
"Got tb %s hash vgroup, vgId:%d, epNum %d, current %s port %d"
,
tbFullName
,
vgInfo
->
vgId
,
vgInfo
->
epSet
.
numOfEps
,
vgInfo
->
epSet
.
eps
[
vgInfo
->
epSet
.
inUse
].
fqdn
,
vgInfo
->
epSet
.
eps
[
vgInfo
->
epSet
.
inUse
].
port
);
CTG_RET
(
code
);
}
int32_t
ctgGetVgInfosFromHashValue
(
SCatalog
*
pCtg
,
SCtgTaskReq
*
tReq
,
SDBVgInfo
*
dbInfo
,
SCtgTbHashsCtx
*
pCtx
,
...
...
@@ -982,7 +1082,7 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SCtgTaskReq* tReq, SDBVgInfo*
SVgroupInfo
**
p
=
taosArraySearch
(
pVgList
,
&
hashValue
,
ctgHashValueComp
,
TD_EQ
);
if
(
NULL
==
p
)
{
ctgError
(
"no hash range found for hash value [%u], db:%s, numOfVgId:%d"
,
hashValue
,
dbFName
,
ctgError
(
"
2
no hash range found for hash value [%u], db:%s, numOfVgId:%d"
,
hashValue
,
dbFName
,
taosHashGetSize
(
dbInfo
->
vgHash
));
taosArrayDestroy
(
pVgList
);
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录