Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2861534a
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
未验证
提交
2861534a
编写于
6月 14, 2022
作者:
D
dapan1121
提交者:
GitHub
6月 14, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #13781 from taosdata/feature/cacheIndex
feat: cache table index
上级
e5bef6d7
545345de
变更
21
显示空白变更内容
内联
并排
Showing
21 changed file
with
1104 addition
and
510 deletion
+1104
-510
include/common/tmsg.h
include/common/tmsg.h
+12
-6
include/libs/catalog/catalog.h
include/libs/catalog/catalog.h
+7
-4
source/client/src/clientHb.c
source/client/src/clientHb.c
+21
-10
source/common/src/tmsg.c
source/common/src/tmsg.c
+93
-18
source/dnode/mnode/impl/inc/mndSma.h
source/dnode/mnode/impl/inc/mndSma.h
+1
-0
source/dnode/mnode/impl/inc/mndStb.h
source/dnode/mnode/impl/inc/mndStb.h
+1
-1
source/dnode/mnode/impl/src/mndProfile.c
source/dnode/mnode/impl/src/mndProfile.c
+1
-1
source/dnode/mnode/impl/src/mndSma.c
source/dnode/mnode/impl/src/mndSma.c
+18
-4
source/dnode/mnode/impl/src/mndStb.c
source/dnode/mnode/impl/src/mndStb.c
+54
-14
source/libs/catalog/inc/catalogInt.h
source/libs/catalog/inc/catalogInt.h
+51
-21
source/libs/catalog/src/catalog.c
source/libs/catalog/src/catalog.c
+83
-17
source/libs/catalog/src/ctgAsync.c
source/libs/catalog/src/ctgAsync.c
+34
-19
source/libs/catalog/src/ctgCache.c
source/libs/catalog/src/ctgCache.c
+626
-341
source/libs/catalog/src/ctgDbg.c
source/libs/catalog/src/ctgDbg.c
+10
-10
source/libs/catalog/src/ctgRemote.c
source/libs/catalog/src/ctgRemote.c
+3
-2
source/libs/catalog/src/ctgUtil.c
source/libs/catalog/src/ctgUtil.c
+73
-31
source/libs/catalog/test/catalogTests.cpp
source/libs/catalog/test/catalogTests.cpp
+6
-6
source/libs/qcom/src/querymsg.c
source/libs/qcom/src/querymsg.c
+2
-4
source/libs/qworker/src/qworker.c
source/libs/qworker/src/qworker.c
+0
-1
source/libs/scalar/src/filter.c
source/libs/scalar/src/filter.c
+5
-0
source/util/src/tarray.c
source/util/src/tarray.c
+3
-0
未找到文件。
include/common/tmsg.h
浏览文件 @
2861534a
...
@@ -1134,14 +1134,16 @@ void tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
...
@@ -1134,14 +1134,16 @@ void tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
int32_t
tSerializeSTableMetaRsp
(
void
*
buf
,
int32_t
bufLen
,
STableMetaRsp
*
pRsp
);
int32_t
tSerializeSTableMetaRsp
(
void
*
buf
,
int32_t
bufLen
,
STableMetaRsp
*
pRsp
);
int32_t
tDeserializeSTableMetaRsp
(
void
*
buf
,
int32_t
bufLen
,
STableMetaRsp
*
pRsp
);
int32_t
tDeserializeSTableMetaRsp
(
void
*
buf
,
int32_t
bufLen
,
STableMetaRsp
*
pRsp
);
void
tFreeSTableMetaRsp
(
STableMetaRsp
*
pRsp
);
void
tFreeSTableMetaRsp
(
STableMetaRsp
*
pRsp
);
void
tFreeSTableIndexRsp
(
void
*
info
);
typedef
struct
{
typedef
struct
{
SArray
*
pArray
;
// Array of STableMetaRsp
SArray
*
pMetaRsp
;
// Array of STableMetaRsp
}
STableMetaBatchRsp
;
SArray
*
pIndexRsp
;
// Array of STableIndexRsp;
}
SSTbHbRsp
;
int32_t
tSerializeS
TableMetaBatchRsp
(
void
*
buf
,
int32_t
bufLen
,
STableMetaBatch
Rsp
*
pRsp
);
int32_t
tSerializeS
STbHbRsp
(
void
*
buf
,
int32_t
bufLen
,
SSTbHb
Rsp
*
pRsp
);
int32_t
tDeserializeS
TableMetaBatchRsp
(
void
*
buf
,
int32_t
bufLen
,
STableMetaBatch
Rsp
*
pRsp
);
int32_t
tDeserializeS
STbHbRsp
(
void
*
buf
,
int32_t
bufLen
,
SSTbHb
Rsp
*
pRsp
);
void
tFreeS
TableMetaBatchRsp
(
STableMetaBatch
Rsp
*
pRsp
);
void
tFreeS
STbHbRsp
(
SSTbHb
Rsp
*
pRsp
);
typedef
struct
{
typedef
struct
{
int32_t
numOfTables
;
int32_t
numOfTables
;
...
@@ -2502,6 +2504,10 @@ typedef struct {
...
@@ -2502,6 +2504,10 @@ typedef struct {
}
STableIndexInfo
;
}
STableIndexInfo
;
typedef
struct
{
typedef
struct
{
char
tbName
[
TSDB_TABLE_NAME_LEN
];
char
dbFName
[
TSDB_DB_FNAME_LEN
];
uint64_t
suid
;
int32_t
version
;
SArray
*
pIndex
;
SArray
*
pIndex
;
}
STableIndexRsp
;
}
STableIndexRsp
;
...
...
include/libs/catalog/catalog.h
浏览文件 @
2861534a
...
@@ -98,14 +98,15 @@ typedef struct SCatalogCfg {
...
@@ -98,14 +98,15 @@ typedef struct SCatalogCfg {
uint32_t
stbRentSec
;
uint32_t
stbRentSec
;
}
SCatalogCfg
;
}
SCatalogCfg
;
typedef
struct
SSTable
Meta
Version
{
typedef
struct
SSTableVersion
{
char
dbFName
[
TSDB_DB_FNAME_LEN
];
char
dbFName
[
TSDB_DB_FNAME_LEN
];
char
stbName
[
TSDB_TABLE_NAME_LEN
];
char
stbName
[
TSDB_TABLE_NAME_LEN
];
uint64_t
dbId
;
uint64_t
dbId
;
uint64_t
suid
;
uint64_t
suid
;
int16_t
sversion
;
int16_t
sversion
;
int16_t
tversion
;
int16_t
tversion
;
}
SSTableMetaVersion
;
int32_t
smaVer
;
}
SSTableVersion
;
typedef
struct
SDbVgVersion
{
typedef
struct
SDbVgVersion
{
char
dbFName
[
TSDB_DB_FNAME_LEN
];
char
dbFName
[
TSDB_DB_FNAME_LEN
];
...
@@ -267,7 +268,7 @@ int32_t catalogAsyncGetAllMeta(SCatalog* pCtg, SRequestConnInfo* pConn, uint64_t
...
@@ -267,7 +268,7 @@ int32_t catalogAsyncGetAllMeta(SCatalog* pCtg, SRequestConnInfo* pConn, uint64_t
int32_t
catalogGetQnodeList
(
SCatalog
*
pCatalog
,
SRequestConnInfo
*
pConn
,
SArray
*
pQnodeList
);
int32_t
catalogGetQnodeList
(
SCatalog
*
pCatalog
,
SRequestConnInfo
*
pConn
,
SArray
*
pQnodeList
);
int32_t
catalogGetExpiredSTables
(
SCatalog
*
pCatalog
,
SSTable
MetaVersion
**
stables
,
uint32_t
*
num
);
int32_t
catalogGetExpiredSTables
(
SCatalog
*
pCatalog
,
SSTable
Version
**
stables
,
uint32_t
*
num
);
int32_t
catalogGetExpiredDBs
(
SCatalog
*
pCatalog
,
SDbVgVersion
**
dbs
,
uint32_t
*
num
);
int32_t
catalogGetExpiredDBs
(
SCatalog
*
pCatalog
,
SDbVgVersion
**
dbs
,
uint32_t
*
num
);
...
@@ -279,6 +280,8 @@ int32_t catalogGetIndexMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const char*
...
@@ -279,6 +280,8 @@ int32_t catalogGetIndexMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const char*
int32_t
catalogGetTableIndex
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
const
SName
*
pTableName
,
SArray
**
pRes
);
int32_t
catalogGetTableIndex
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
const
SName
*
pTableName
,
SArray
**
pRes
);
int32_t
catalogUpdateTableIndex
(
SCatalog
*
pCtg
,
STableIndexRsp
*
pRsp
);
int32_t
catalogGetUdfInfo
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
const
char
*
funcName
,
SFuncInfo
*
pInfo
);
int32_t
catalogGetUdfInfo
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
const
char
*
funcName
,
SFuncInfo
*
pInfo
);
int32_t
catalogChkAuth
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
const
char
*
user
,
const
char
*
dbFName
,
AUTH_TYPE
type
,
bool
*
pass
);
int32_t
catalogChkAuth
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
const
char
*
user
,
const
char
*
dbFName
,
AUTH_TYPE
type
,
bool
*
pass
);
...
...
source/client/src/clientHb.c
浏览文件 @
2861534a
...
@@ -99,15 +99,15 @@ static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog
...
@@ -99,15 +99,15 @@ static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog
static
int32_t
hbProcessStbInfoRsp
(
void
*
value
,
int32_t
valueLen
,
struct
SCatalog
*
pCatalog
)
{
static
int32_t
hbProcessStbInfoRsp
(
void
*
value
,
int32_t
valueLen
,
struct
SCatalog
*
pCatalog
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
S
TableMetaBatchRsp
batchMeta
Rsp
=
{
0
};
S
STbHbRsp
hb
Rsp
=
{
0
};
if
(
tDeserializeS
TableMetaBatchRsp
(
value
,
valueLen
,
&
batchMeta
Rsp
)
!=
0
)
{
if
(
tDeserializeS
STbHbRsp
(
value
,
valueLen
,
&
hb
Rsp
)
!=
0
)
{
terrno
=
TSDB_CODE_INVALID_MSG
;
terrno
=
TSDB_CODE_INVALID_MSG
;
return
-
1
;
return
-
1
;
}
}
int32_t
numOf
Batchs
=
taosArrayGetSize
(
batchMetaRsp
.
pArray
);
int32_t
numOf
Meta
=
taosArrayGetSize
(
hbRsp
.
pMetaRsp
);
for
(
int32_t
i
=
0
;
i
<
numOf
Batchs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOf
Meta
;
++
i
)
{
STableMetaRsp
*
rsp
=
taosArrayGet
(
batchMetaRsp
.
pArray
,
i
);
STableMetaRsp
*
rsp
=
taosArrayGet
(
hbRsp
.
pMetaRsp
,
i
);
if
(
rsp
->
numOfColumns
<
0
)
{
if
(
rsp
->
numOfColumns
<
0
)
{
tscDebug
(
"hb remove stb, db:%s, stb:%s"
,
rsp
->
dbFName
,
rsp
->
stbName
);
tscDebug
(
"hb remove stb, db:%s, stb:%s"
,
rsp
->
dbFName
,
rsp
->
stbName
);
...
@@ -116,7 +116,7 @@ static int32_t hbProcessStbInfoRsp(void *value, int32_t valueLen, struct SCatalo
...
@@ -116,7 +116,7 @@ static int32_t hbProcessStbInfoRsp(void *value, int32_t valueLen, struct SCatalo
tscDebug
(
"hb update stb, db:%s, stb:%s"
,
rsp
->
dbFName
,
rsp
->
stbName
);
tscDebug
(
"hb update stb, db:%s, stb:%s"
,
rsp
->
dbFName
,
rsp
->
stbName
);
if
(
rsp
->
pSchemas
[
0
].
colId
!=
PRIMARYKEY_TIMESTAMP_COL_ID
)
{
if
(
rsp
->
pSchemas
[
0
].
colId
!=
PRIMARYKEY_TIMESTAMP_COL_ID
)
{
tscError
(
"invalid colId[%"
PRIi16
"] for the first column in table meta rsp msg"
,
rsp
->
pSchemas
[
0
].
colId
);
tscError
(
"invalid colId[%"
PRIi16
"] for the first column in table meta rsp msg"
,
rsp
->
pSchemas
[
0
].
colId
);
tFreeS
TableMetaBatchRsp
(
&
batchMeta
Rsp
);
tFreeS
STbHbRsp
(
&
hb
Rsp
);
return
TSDB_CODE_TSC_INVALID_VALUE
;
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
}
...
@@ -124,7 +124,17 @@ static int32_t hbProcessStbInfoRsp(void *value, int32_t valueLen, struct SCatalo
...
@@ -124,7 +124,17 @@ static int32_t hbProcessStbInfoRsp(void *value, int32_t valueLen, struct SCatalo
}
}
}
}
tFreeSTableMetaBatchRsp
(
&
batchMetaRsp
);
int32_t
numOfIndex
=
taosArrayGetSize
(
hbRsp
.
pIndexRsp
);
for
(
int32_t
i
=
0
;
i
<
numOfIndex
;
++
i
)
{
STableIndexRsp
*
rsp
=
taosArrayGet
(
hbRsp
.
pIndexRsp
,
i
);
catalogUpdateTableIndex
(
pCatalog
,
rsp
);
}
taosArrayDestroy
(
hbRsp
.
pIndexRsp
);
hbRsp
.
pIndexRsp
=
NULL
;
tFreeSSTbHbRsp
(
&
hbRsp
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -455,7 +465,7 @@ int32_t hbGetExpiredDBInfo(SClientHbKey *connKey, struct SCatalog *pCatalog, SCl
...
@@ -455,7 +465,7 @@ int32_t hbGetExpiredDBInfo(SClientHbKey *connKey, struct SCatalog *pCatalog, SCl
}
}
int32_t
hbGetExpiredStbInfo
(
SClientHbKey
*
connKey
,
struct
SCatalog
*
pCatalog
,
SClientHbReq
*
req
)
{
int32_t
hbGetExpiredStbInfo
(
SClientHbKey
*
connKey
,
struct
SCatalog
*
pCatalog
,
SClientHbReq
*
req
)
{
SSTable
Meta
Version
*
stbs
=
NULL
;
SSTableVersion
*
stbs
=
NULL
;
uint32_t
stbNum
=
0
;
uint32_t
stbNum
=
0
;
int32_t
code
=
0
;
int32_t
code
=
0
;
...
@@ -469,15 +479,16 @@ int32_t hbGetExpiredStbInfo(SClientHbKey *connKey, struct SCatalog *pCatalog, SC
...
@@ -469,15 +479,16 @@ int32_t hbGetExpiredStbInfo(SClientHbKey *connKey, struct SCatalog *pCatalog, SC
}
}
for
(
int32_t
i
=
0
;
i
<
stbNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
stbNum
;
++
i
)
{
SSTable
Meta
Version
*
stb
=
&
stbs
[
i
];
SSTableVersion
*
stb
=
&
stbs
[
i
];
stb
->
suid
=
htobe64
(
stb
->
suid
);
stb
->
suid
=
htobe64
(
stb
->
suid
);
stb
->
sversion
=
htons
(
stb
->
sversion
);
stb
->
sversion
=
htons
(
stb
->
sversion
);
stb
->
tversion
=
htons
(
stb
->
tversion
);
stb
->
tversion
=
htons
(
stb
->
tversion
);
stb
->
smaVer
=
htonl
(
stb
->
smaVer
);
}
}
SKv
kv
=
{
SKv
kv
=
{
.
key
=
HEARTBEAT_KEY_STBINFO
,
.
key
=
HEARTBEAT_KEY_STBINFO
,
.
valueLen
=
sizeof
(
SSTable
Meta
Version
)
*
stbNum
,
.
valueLen
=
sizeof
(
SSTableVersion
)
*
stbNum
,
.
value
=
stbs
,
.
value
=
stbs
,
};
};
...
...
source/common/src/tmsg.c
浏览文件 @
2861534a
...
@@ -2438,6 +2438,10 @@ int32_t tSerializeSTableIndexRsp(void *buf, int32_t bufLen, const STableIndexRsp
...
@@ -2438,6 +2438,10 @@ int32_t tSerializeSTableIndexRsp(void *buf, int32_t bufLen, const STableIndexRsp
tEncoderInit
(
&
encoder
,
buf
,
bufLen
);
tEncoderInit
(
&
encoder
,
buf
,
bufLen
);
if
(
tStartEncode
(
&
encoder
)
<
0
)
return
-
1
;
if
(
tStartEncode
(
&
encoder
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
&
encoder
,
pRsp
->
tbName
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
&
encoder
,
pRsp
->
dbFName
)
<
0
)
return
-
1
;
if
(
tEncodeU64
(
&
encoder
,
pRsp
->
suid
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
pRsp
->
version
)
<
0
)
return
-
1
;
int32_t
num
=
taosArrayGetSize
(
pRsp
->
pIndex
);
int32_t
num
=
taosArrayGetSize
(
pRsp
->
pIndex
);
if
(
tEncodeI32
(
&
encoder
,
num
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
num
)
<
0
)
return
-
1
;
if
(
num
>
0
)
{
if
(
num
>
0
)
{
...
@@ -2472,6 +2476,10 @@ int32_t tDeserializeSTableIndexRsp(void *buf, int32_t bufLen, STableIndexRsp *pR
...
@@ -2472,6 +2476,10 @@ int32_t tDeserializeSTableIndexRsp(void *buf, int32_t bufLen, STableIndexRsp *pR
tDecoderInit
(
&
decoder
,
buf
,
bufLen
);
tDecoderInit
(
&
decoder
,
buf
,
bufLen
);
if
(
tStartDecode
(
&
decoder
)
<
0
)
return
-
1
;
if
(
tStartDecode
(
&
decoder
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
&
decoder
,
pRsp
->
tbName
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
&
decoder
,
pRsp
->
dbFName
)
<
0
)
return
-
1
;
if
(
tDecodeU64
(
&
decoder
,
&
pRsp
->
suid
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
pRsp
->
version
)
<
0
)
return
-
1
;
int32_t
num
=
0
;
int32_t
num
=
0
;
if
(
tDecodeI32
(
&
decoder
,
&
num
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
num
)
<
0
)
return
-
1
;
if
(
num
>
0
)
{
if
(
num
>
0
)
{
...
@@ -2631,18 +2639,35 @@ int32_t tSerializeSTableMetaRsp(void *buf, int32_t bufLen, STableMetaRsp *pRsp)
...
@@ -2631,18 +2639,35 @@ int32_t tSerializeSTableMetaRsp(void *buf, int32_t bufLen, STableMetaRsp *pRsp)
return
tlen
;
return
tlen
;
}
}
int32_t
tSerializeS
TableMetaBatchRsp
(
void
*
buf
,
int32_t
bufLen
,
STableMetaBatch
Rsp
*
pRsp
)
{
int32_t
tSerializeS
STbHbRsp
(
void
*
buf
,
int32_t
bufLen
,
SSTbHb
Rsp
*
pRsp
)
{
SEncoder
encoder
=
{
0
};
SEncoder
encoder
=
{
0
};
tEncoderInit
(
&
encoder
,
buf
,
bufLen
);
tEncoderInit
(
&
encoder
,
buf
,
bufLen
);
if
(
tStartEncode
(
&
encoder
)
<
0
)
return
-
1
;
if
(
tStartEncode
(
&
encoder
)
<
0
)
return
-
1
;
int32_t
numOf
Batch
=
taosArrayGetSize
(
pRsp
->
pArray
);
int32_t
numOf
Meta
=
taosArrayGetSize
(
pRsp
->
pMetaRsp
);
if
(
tEncodeI32
(
&
encoder
,
numOf
Batch
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
numOf
Meta
)
<
0
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
numOf
Batch
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOf
Meta
;
++
i
)
{
STableMetaRsp
*
pMetaRsp
=
taosArrayGet
(
pRsp
->
p
Array
,
i
);
STableMetaRsp
*
pMetaRsp
=
taosArrayGet
(
pRsp
->
p
MetaRsp
,
i
);
if
(
tEncodeSTableMetaRsp
(
&
encoder
,
pMetaRsp
)
<
0
)
return
-
1
;
if
(
tEncodeSTableMetaRsp
(
&
encoder
,
pMetaRsp
)
<
0
)
return
-
1
;
}
}
int32_t
numOfIndex
=
taosArrayGetSize
(
pRsp
->
pIndexRsp
);
if
(
tEncodeI32
(
&
encoder
,
numOfIndex
)
<
0
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
numOfIndex
;
++
i
)
{
STableIndexRsp
*
pIndexRsp
=
taosArrayGet
(
pRsp
->
pIndexRsp
,
i
);
if
(
tEncodeCStr
(
&
encoder
,
pIndexRsp
->
tbName
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
&
encoder
,
pIndexRsp
->
dbFName
)
<
0
)
return
-
1
;
if
(
tEncodeU64
(
&
encoder
,
pIndexRsp
->
suid
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
pIndexRsp
->
version
)
<
0
)
return
-
1
;
int32_t
num
=
taosArrayGetSize
(
pIndexRsp
->
pIndex
);
if
(
tEncodeI32
(
&
encoder
,
num
)
<
0
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
STableIndexInfo
*
pInfo
=
(
STableIndexInfo
*
)
taosArrayGet
(
pIndexRsp
->
pIndex
,
i
);
if
(
tSerializeSTableIndexInfo
(
&
encoder
,
pInfo
)
<
0
)
return
-
1
;
}
}
tEndEncode
(
&
encoder
);
tEndEncode
(
&
encoder
);
int32_t
tlen
=
encoder
.
pos
;
int32_t
tlen
=
encoder
.
pos
;
...
@@ -2662,26 +2687,58 @@ int32_t tDeserializeSTableMetaRsp(void *buf, int32_t bufLen, STableMetaRsp *pRsp
...
@@ -2662,26 +2687,58 @@ int32_t tDeserializeSTableMetaRsp(void *buf, int32_t bufLen, STableMetaRsp *pRsp
return
0
;
return
0
;
}
}
int32_t
tDeserializeS
TableMetaBatchRsp
(
void
*
buf
,
int32_t
bufLen
,
STableMetaBatch
Rsp
*
pRsp
)
{
int32_t
tDeserializeS
STbHbRsp
(
void
*
buf
,
int32_t
bufLen
,
SSTbHb
Rsp
*
pRsp
)
{
SDecoder
decoder
=
{
0
};
SDecoder
decoder
=
{
0
};
tDecoderInit
(
&
decoder
,
buf
,
bufLen
);
tDecoderInit
(
&
decoder
,
buf
,
bufLen
);
if
(
tStartDecode
(
&
decoder
)
<
0
)
return
-
1
;
if
(
tStartDecode
(
&
decoder
)
<
0
)
return
-
1
;
int32_t
numOfBatch
=
taosArrayGetSize
(
pRsp
->
pArray
);
int32_t
numOfMeta
=
0
;
if
(
tDecodeI32
(
&
decoder
,
&
numOfBatch
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
numOfMeta
)
<
0
)
return
-
1
;
pRsp
->
pMetaRsp
=
taosArrayInit
(
numOfMeta
,
sizeof
(
STableMetaRsp
));
pRsp
->
pArray
=
taosArrayInit
(
numOfBatch
,
sizeof
(
STableMetaRsp
));
if
(
pRsp
->
pMetaRsp
==
NULL
)
{
if
(
pRsp
->
pArray
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
return
-
1
;
}
}
for
(
int32_t
i
=
0
;
i
<
numOf
Batch
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOf
Meta
;
++
i
)
{
STableMetaRsp
tableMetaRsp
=
{
0
};
STableMetaRsp
tableMetaRsp
=
{
0
};
if
(
tDecodeSTableMetaRsp
(
&
decoder
,
&
tableMetaRsp
)
<
0
)
return
-
1
;
if
(
tDecodeSTableMetaRsp
(
&
decoder
,
&
tableMetaRsp
)
<
0
)
return
-
1
;
taosArrayPush
(
pRsp
->
pArray
,
&
tableMetaRsp
);
taosArrayPush
(
pRsp
->
pMetaRsp
,
&
tableMetaRsp
);
}
int32_t
numOfIndex
=
0
;
if
(
tDecodeI32
(
&
decoder
,
&
numOfIndex
)
<
0
)
return
-
1
;
pRsp
->
pIndexRsp
=
taosArrayInit
(
numOfIndex
,
sizeof
(
STableIndexRsp
));
if
(
pRsp
->
pIndexRsp
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
}
for
(
int32_t
i
=
0
;
i
<
numOfIndex
;
++
i
)
{
STableIndexRsp
tableIndexRsp
=
{
0
};
if
(
tDecodeCStrTo
(
&
decoder
,
tableIndexRsp
.
tbName
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
&
decoder
,
tableIndexRsp
.
dbFName
)
<
0
)
return
-
1
;
if
(
tDecodeU64
(
&
decoder
,
&
tableIndexRsp
.
suid
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
tableIndexRsp
.
version
)
<
0
)
return
-
1
;
int32_t
num
=
0
;
if
(
tDecodeI32
(
&
decoder
,
&
num
)
<
0
)
return
-
1
;
if
(
num
>
0
)
{
tableIndexRsp
.
pIndex
=
taosArrayInit
(
num
,
sizeof
(
STableIndexInfo
));
if
(
NULL
==
tableIndexRsp
.
pIndex
)
return
-
1
;
STableIndexInfo
info
;
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
if
(
tDeserializeSTableIndexInfo
(
&
decoder
,
&
info
)
<
0
)
return
-
1
;
if
(
NULL
==
taosArrayPush
(
tableIndexRsp
.
pIndex
,
&
info
))
{
taosMemoryFree
(
info
.
expr
);
return
-
1
;
}
}
}
taosArrayPush
(
pRsp
->
pIndexRsp
,
&
tableIndexRsp
);
}
tEndDecode
(
&
decoder
);
tEndDecode
(
&
decoder
);
tDecoderClear
(
&
decoder
);
tDecoderClear
(
&
decoder
);
...
@@ -2690,14 +2747,32 @@ int32_t tDeserializeSTableMetaBatchRsp(void *buf, int32_t bufLen, STableMetaBatc
...
@@ -2690,14 +2747,32 @@ int32_t tDeserializeSTableMetaBatchRsp(void *buf, int32_t bufLen, STableMetaBatc
void
tFreeSTableMetaRsp
(
STableMetaRsp
*
pRsp
)
{
taosMemoryFreeClear
(
pRsp
->
pSchemas
);
}
void
tFreeSTableMetaRsp
(
STableMetaRsp
*
pRsp
)
{
taosMemoryFreeClear
(
pRsp
->
pSchemas
);
}
void
tFreeSTableMetaBatchRsp
(
STableMetaBatchRsp
*
pRsp
)
{
void
tFreeSTableIndexRsp
(
void
*
info
)
{
int32_t
numOfBatch
=
taosArrayGetSize
(
pRsp
->
pArray
);
if
(
NULL
==
info
)
{
for
(
int32_t
i
=
0
;
i
<
numOfBatch
;
++
i
)
{
return
;
STableMetaRsp
*
pMetaRsp
=
taosArrayGet
(
pRsp
->
pArray
,
i
);
}
STableIndexRsp
*
pInfo
=
(
STableIndexRsp
*
)
info
;
taosArrayDestroyEx
(
pInfo
->
pIndex
,
tFreeSTableIndexInfo
);
}
void
tFreeSSTbHbRsp
(
SSTbHbRsp
*
pRsp
)
{
int32_t
numOfMeta
=
taosArrayGetSize
(
pRsp
->
pMetaRsp
);
for
(
int32_t
i
=
0
;
i
<
numOfMeta
;
++
i
)
{
STableMetaRsp
*
pMetaRsp
=
taosArrayGet
(
pRsp
->
pMetaRsp
,
i
);
tFreeSTableMetaRsp
(
pMetaRsp
);
tFreeSTableMetaRsp
(
pMetaRsp
);
}
}
taosArrayDestroy
(
pRsp
->
pArray
);
taosArrayDestroy
(
pRsp
->
pMetaRsp
);
int32_t
numOfIndex
=
taosArrayGetSize
(
pRsp
->
pIndexRsp
);
for
(
int32_t
i
=
0
;
i
<
numOfIndex
;
++
i
)
{
STableIndexRsp
*
pIndexRsp
=
taosArrayGet
(
pRsp
->
pIndexRsp
,
i
);
tFreeSTableIndexRsp
(
pIndexRsp
);
}
taosArrayDestroy
(
pRsp
->
pIndexRsp
);
}
}
int32_t
tSerializeSShowRsp
(
void
*
buf
,
int32_t
bufLen
,
SShowRsp
*
pRsp
)
{
int32_t
tSerializeSShowRsp
(
void
*
buf
,
int32_t
bufLen
,
SShowRsp
*
pRsp
)
{
...
...
source/dnode/mnode/impl/inc/mndSma.h
浏览文件 @
2861534a
...
@@ -26,6 +26,7 @@ int32_t mndInitSma(SMnode *pMnode);
...
@@ -26,6 +26,7 @@ int32_t mndInitSma(SMnode *pMnode);
void
mndCleanupSma
(
SMnode
*
pMnode
);
void
mndCleanupSma
(
SMnode
*
pMnode
);
SSmaObj
*
mndAcquireSma
(
SMnode
*
pMnode
,
char
*
smaName
);
SSmaObj
*
mndAcquireSma
(
SMnode
*
pMnode
,
char
*
smaName
);
void
mndReleaseSma
(
SMnode
*
pMnode
,
SSmaObj
*
pSma
);
void
mndReleaseSma
(
SMnode
*
pMnode
,
SSmaObj
*
pSma
);
int32_t
mndGetTableSma
(
SMnode
*
pMnode
,
char
*
tbFName
,
STableIndexRsp
*
rsp
,
bool
*
exist
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/dnode/mnode/impl/inc/mndStb.h
浏览文件 @
2861534a
...
@@ -27,7 +27,7 @@ void mndCleanupStb(SMnode *pMnode);
...
@@ -27,7 +27,7 @@ void mndCleanupStb(SMnode *pMnode);
SStbObj
*
mndAcquireStb
(
SMnode
*
pMnode
,
char
*
stbName
);
SStbObj
*
mndAcquireStb
(
SMnode
*
pMnode
,
char
*
stbName
);
void
mndReleaseStb
(
SMnode
*
pMnode
,
SStbObj
*
pStb
);
void
mndReleaseStb
(
SMnode
*
pMnode
,
SStbObj
*
pStb
);
SSdbRaw
*
mndStbActionEncode
(
SStbObj
*
pStb
);
SSdbRaw
*
mndStbActionEncode
(
SStbObj
*
pStb
);
int32_t
mndValidateStbInfo
(
SMnode
*
pMnode
,
SSTable
Meta
Version
*
pStbs
,
int32_t
numOfStbs
,
void
**
ppRsp
,
int32_t
mndValidateStbInfo
(
SMnode
*
pMnode
,
SSTableVersion
*
pStbs
,
int32_t
numOfStbs
,
void
**
ppRsp
,
int32_t
*
pRspLen
);
int32_t
*
pRspLen
);
int32_t
mndGetNumOfStbs
(
SMnode
*
pMnode
,
char
*
dbName
,
int32_t
*
pNumOfStbs
);
int32_t
mndGetNumOfStbs
(
SMnode
*
pMnode
,
char
*
dbName
,
int32_t
*
pNumOfStbs
);
...
...
source/dnode/mnode/impl/src/mndProfile.c
浏览文件 @
2861534a
...
@@ -433,7 +433,7 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb
...
@@ -433,7 +433,7 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb
case
HEARTBEAT_KEY_STBINFO
:
{
case
HEARTBEAT_KEY_STBINFO
:
{
void
*
rspMsg
=
NULL
;
void
*
rspMsg
=
NULL
;
int32_t
rspLen
=
0
;
int32_t
rspLen
=
0
;
mndValidateStbInfo
(
pMnode
,
kv
->
value
,
kv
->
valueLen
/
sizeof
(
SSTable
Meta
Version
),
&
rspMsg
,
&
rspLen
);
mndValidateStbInfo
(
pMnode
,
kv
->
value
,
kv
->
valueLen
/
sizeof
(
SSTableVersion
),
&
rspMsg
,
&
rspLen
);
if
(
rspMsg
&&
rspLen
>
0
)
{
if
(
rspMsg
&&
rspLen
>
0
)
{
SKv
kv1
=
{.
key
=
HEARTBEAT_KEY_STBINFO
,
.
valueLen
=
rspLen
,
.
value
=
rspMsg
};
SKv
kv1
=
{.
key
=
HEARTBEAT_KEY_STBINFO
,
.
valueLen
=
rspLen
,
.
value
=
rspMsg
};
taosArrayPush
(
hbRsp
.
info
,
&
kv1
);
taosArrayPush
(
hbRsp
.
info
,
&
kv1
);
...
...
source/dnode/mnode/impl/src/mndSma.c
浏览文件 @
2861534a
...
@@ -532,6 +532,7 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea
...
@@ -532,6 +532,7 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea
SStreamObj
streamObj
=
{
0
};
SStreamObj
streamObj
=
{
0
};
tstrncpy
(
streamObj
.
name
,
pCreate
->
name
,
TSDB_STREAM_FNAME_LEN
);
tstrncpy
(
streamObj
.
name
,
pCreate
->
name
,
TSDB_STREAM_FNAME_LEN
);
tstrncpy
(
streamObj
.
sourceDb
,
pDb
->
name
,
TSDB_DB_FNAME_LEN
);
tstrncpy
(
streamObj
.
sourceDb
,
pDb
->
name
,
TSDB_DB_FNAME_LEN
);
tstrncpy
(
streamObj
.
targetDb
,
streamObj
.
sourceDb
,
TSDB_DB_FNAME_LEN
);
streamObj
.
createTime
=
taosGetTimestampMs
();
streamObj
.
createTime
=
taosGetTimestampMs
();
streamObj
.
updateTime
=
streamObj
.
createTime
;
streamObj
.
updateTime
=
streamObj
.
createTime
;
streamObj
.
uid
=
mndGenerateUid
(
pCreate
->
name
,
strlen
(
pCreate
->
name
));
streamObj
.
uid
=
mndGenerateUid
(
pCreate
->
name
,
strlen
(
pCreate
->
name
));
...
@@ -899,18 +900,31 @@ static int32_t mndGetSma(SMnode *pMnode, SUserIndexReq *indexReq, SUserIndexRsp
...
@@ -899,18 +900,31 @@ static int32_t mndGetSma(SMnode *pMnode, SUserIndexReq *indexReq, SUserIndexRsp
return
code
;
return
code
;
}
}
static
int32_t
mndGetTableSma
(
SMnode
*
pMnode
,
STableIndexReq
*
indexReq
,
STableIndexRsp
*
rsp
,
bool
*
exist
)
{
int32_t
mndGetTableSma
(
SMnode
*
pMnode
,
char
*
tbFName
,
STableIndexRsp
*
rsp
,
bool
*
exist
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
SSmaObj
*
pSma
=
NULL
;
SSmaObj
*
pSma
=
NULL
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
void
*
pIter
=
NULL
;
void
*
pIter
=
NULL
;
STableIndexInfo
info
;
STableIndexInfo
info
;
SStbObj
*
pStb
=
mndAcquireStb
(
pMnode
,
tbFName
);
if
(
NULL
==
pStb
)
{
*
exist
=
false
;
return
TSDB_CODE_SUCCESS
;
}
strcpy
(
rsp
->
dbFName
,
pStb
->
db
);
strcpy
(
rsp
->
tbName
,
pStb
->
name
+
strlen
(
pStb
->
db
)
+
1
);
rsp
->
suid
=
pStb
->
uid
;
rsp
->
version
=
pStb
->
smaVer
;
mndReleaseStb
(
pMnode
,
pStb
);
while
(
1
)
{
while
(
1
)
{
pIter
=
sdbFetch
(
pSdb
,
SDB_SMA
,
pIter
,
(
void
**
)
&
pSma
);
pIter
=
sdbFetch
(
pSdb
,
SDB_SMA
,
pIter
,
(
void
**
)
&
pSma
);
if
(
pIter
==
NULL
)
break
;
if
(
pIter
==
NULL
)
break
;
if
(
pSma
->
stb
[
0
]
!=
indexReq
->
tbFName
[
0
]
||
strcmp
(
pSma
->
stb
,
indexReq
->
tbFName
))
{
if
(
pSma
->
stb
[
0
]
!=
tbFName
[
0
]
||
strcmp
(
pSma
->
stb
,
tbFName
))
{
continue
;
continue
;
}
}
...
@@ -1022,7 +1036,7 @@ static int32_t mndProcessGetTbSmaReq(SRpcMsg *pReq) {
...
@@ -1022,7 +1036,7 @@ static int32_t mndProcessGetTbSmaReq(SRpcMsg *pReq) {
goto
_OVER
;
goto
_OVER
;
}
}
code
=
mndGetTableSma
(
pMnode
,
&
indexReq
,
&
rsp
,
&
exist
);
code
=
mndGetTableSma
(
pMnode
,
indexReq
.
tbFName
,
&
rsp
,
&
exist
);
if
(
code
)
{
if
(
code
)
{
goto
_OVER
;
goto
_OVER
;
}
}
...
...
source/dnode/mnode/impl/src/mndStb.c
浏览文件 @
2861534a
...
@@ -27,6 +27,7 @@
...
@@ -27,6 +27,7 @@
#include "mndTrans.h"
#include "mndTrans.h"
#include "mndUser.h"
#include "mndUser.h"
#include "mndVgroup.h"
#include "mndVgroup.h"
#include "mndSma.h"
#include "tname.h"
#include "tname.h"
#define STB_VER_NUMBER 1
#define STB_VER_NUMBER 1
...
@@ -1271,7 +1272,7 @@ static int32_t mndBuildStbSchemaImp(SDbObj *pDb, SStbObj *pStb, const char *tbNa
...
@@ -1271,7 +1272,7 @@ static int32_t mndBuildStbSchemaImp(SDbObj *pDb, SStbObj *pStb, const char *tbNa
return
0
;
return
0
;
}
}
static
int32_t
mndBuildStbSchema
(
SMnode
*
pMnode
,
const
char
*
dbFName
,
const
char
*
tbName
,
STableMetaRsp
*
pRsp
)
{
static
int32_t
mndBuildStbSchema
(
SMnode
*
pMnode
,
const
char
*
dbFName
,
const
char
*
tbName
,
STableMetaRsp
*
pRsp
,
int32_t
*
smaVer
)
{
char
tbFName
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
char
tbFName
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
snprintf
(
tbFName
,
sizeof
(
tbFName
),
"%s.%s"
,
dbFName
,
tbName
);
snprintf
(
tbFName
,
sizeof
(
tbFName
),
"%s.%s"
,
dbFName
,
tbName
);
...
@@ -1288,6 +1289,10 @@ static int32_t mndBuildStbSchema(SMnode *pMnode, const char *dbFName, const char
...
@@ -1288,6 +1289,10 @@ static int32_t mndBuildStbSchema(SMnode *pMnode, const char *dbFName, const char
return
-
1
;
return
-
1
;
}
}
if
(
smaVer
)
{
*
smaVer
=
pStb
->
smaVer
;
}
int32_t
code
=
mndBuildStbSchemaImp
(
pDb
,
pStb
,
tbName
,
pRsp
);
int32_t
code
=
mndBuildStbSchemaImp
(
pDb
,
pStb
,
tbName
,
pRsp
);
mndReleaseDb
(
pMnode
,
pDb
);
mndReleaseDb
(
pMnode
,
pDb
);
mndReleaseStb
(
pMnode
,
pStb
);
mndReleaseStb
(
pMnode
,
pStb
);
...
@@ -1634,7 +1639,7 @@ static int32_t mndProcessTableMetaReq(SRpcMsg *pReq) {
...
@@ -1634,7 +1639,7 @@ static int32_t mndProcessTableMetaReq(SRpcMsg *pReq) {
}
}
}
else
{
}
else
{
mDebug
(
"stb:%s.%s, start to retrieve meta"
,
infoReq
.
dbFName
,
infoReq
.
tbName
);
mDebug
(
"stb:%s.%s, start to retrieve meta"
,
infoReq
.
dbFName
,
infoReq
.
tbName
);
if
(
mndBuildStbSchema
(
pMnode
,
infoReq
.
dbFName
,
infoReq
.
tbName
,
&
metaRsp
)
!=
0
)
{
if
(
mndBuildStbSchema
(
pMnode
,
infoReq
.
dbFName
,
infoReq
.
tbName
,
&
metaRsp
,
NULL
)
!=
0
)
{
goto
_OVER
;
goto
_OVER
;
}
}
}
}
...
@@ -1667,51 +1672,86 @@ _OVER:
...
@@ -1667,51 +1672,86 @@ _OVER:
return
code
;
return
code
;
}
}
int32_t
mndValidateStbInfo
(
SMnode
*
pMnode
,
SSTable
Meta
Version
*
pStbVersions
,
int32_t
numOfStbs
,
void
**
ppRsp
,
int32_t
mndValidateStbInfo
(
SMnode
*
pMnode
,
SSTableVersion
*
pStbVersions
,
int32_t
numOfStbs
,
void
**
ppRsp
,
int32_t
*
pRspLen
)
{
int32_t
*
pRspLen
)
{
STableMetaBatchRsp
batchMetaRsp
=
{
0
};
SSTbHbRsp
hbRsp
=
{
0
};
batchMetaRsp
.
pArray
=
taosArrayInit
(
numOfStbs
,
sizeof
(
STableMetaRsp
));
hbRsp
.
pMetaRsp
=
taosArrayInit
(
numOfStbs
,
sizeof
(
STableMetaRsp
));
if
(
batchMetaRsp
.
pArray
==
NULL
)
{
if
(
hbRsp
.
pMetaRsp
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
hbRsp
.
pIndexRsp
=
taosArrayInit
(
numOfStbs
,
sizeof
(
STableIndexRsp
));
if
(
NULL
==
hbRsp
.
pIndexRsp
)
{
taosArrayDestroy
(
hbRsp
.
pMetaRsp
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
return
-
1
;
}
}
for
(
int32_t
i
=
0
;
i
<
numOfStbs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfStbs
;
++
i
)
{
SSTable
Meta
Version
*
pStbVersion
=
&
pStbVersions
[
i
];
SSTableVersion
*
pStbVersion
=
&
pStbVersions
[
i
];
pStbVersion
->
suid
=
be64toh
(
pStbVersion
->
suid
);
pStbVersion
->
suid
=
be64toh
(
pStbVersion
->
suid
);
pStbVersion
->
sversion
=
ntohs
(
pStbVersion
->
sversion
);
pStbVersion
->
sversion
=
ntohs
(
pStbVersion
->
sversion
);
pStbVersion
->
tversion
=
ntohs
(
pStbVersion
->
tversion
);
pStbVersion
->
tversion
=
ntohs
(
pStbVersion
->
tversion
);
pStbVersion
->
smaVer
=
ntohl
(
pStbVersion
->
smaVer
);
STableMetaRsp
metaRsp
=
{
0
};
STableMetaRsp
metaRsp
=
{
0
};
int32_t
smaVer
=
0
;
mDebug
(
"stb:%s.%s, start to retrieve meta"
,
pStbVersion
->
dbFName
,
pStbVersion
->
stbName
);
mDebug
(
"stb:%s.%s, start to retrieve meta"
,
pStbVersion
->
dbFName
,
pStbVersion
->
stbName
);
if
(
mndBuildStbSchema
(
pMnode
,
pStbVersion
->
dbFName
,
pStbVersion
->
stbName
,
&
metaRsp
)
!=
0
)
{
if
(
mndBuildStbSchema
(
pMnode
,
pStbVersion
->
dbFName
,
pStbVersion
->
stbName
,
&
metaRsp
,
&
smaVer
)
!=
0
)
{
metaRsp
.
numOfColumns
=
-
1
;
metaRsp
.
numOfColumns
=
-
1
;
metaRsp
.
suid
=
pStbVersion
->
suid
;
metaRsp
.
suid
=
pStbVersion
->
suid
;
taosArrayPush
(
hbRsp
.
pMetaRsp
,
&
metaRsp
);
continue
;
}
}
if
(
pStbVersion
->
sversion
!=
metaRsp
.
sversion
||
pStbVersion
->
tversion
!=
metaRsp
.
tversion
)
{
if
(
pStbVersion
->
sversion
!=
metaRsp
.
sversion
||
pStbVersion
->
tversion
!=
metaRsp
.
tversion
)
{
taosArrayPush
(
batchMetaRsp
.
pArray
,
&
metaRsp
);
taosArrayPush
(
hbRsp
.
pMetaRsp
,
&
metaRsp
);
}
else
{
}
else
{
tFreeSTableMetaRsp
(
&
metaRsp
);
tFreeSTableMetaRsp
(
&
metaRsp
);
}
}
if
(
pStbVersion
->
smaVer
&&
pStbVersion
->
smaVer
!=
smaVer
)
{
bool
exist
=
false
;
char
tbFName
[
TSDB_TABLE_FNAME_LEN
];
STableIndexRsp
indexRsp
=
{
0
};
indexRsp
.
pIndex
=
taosArrayInit
(
10
,
sizeof
(
STableIndexInfo
));
if
(
NULL
==
indexRsp
.
pIndex
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
sprintf
(
tbFName
,
"%s.%s"
,
pStbVersion
->
dbFName
,
pStbVersion
->
stbName
);
int32_t
code
=
mndGetTableSma
(
pMnode
,
tbFName
,
&
indexRsp
,
&
exist
);
if
(
code
||
!
exist
)
{
indexRsp
.
suid
=
pStbVersion
->
suid
;
indexRsp
.
version
=
-
1
;
indexRsp
.
pIndex
=
NULL
;
}
strcpy
(
indexRsp
.
dbFName
,
pStbVersion
->
dbFName
);
strcpy
(
indexRsp
.
tbName
,
pStbVersion
->
stbName
);
taosArrayPush
(
hbRsp
.
pIndexRsp
,
&
indexRsp
);
}
}
}
int32_t
rspLen
=
tSerializeS
TableMetaBatchRsp
(
NULL
,
0
,
&
batchMeta
Rsp
);
int32_t
rspLen
=
tSerializeS
STbHbRsp
(
NULL
,
0
,
&
hb
Rsp
);
if
(
rspLen
<
0
)
{
if
(
rspLen
<
0
)
{
tFreeS
TableMetaBatchRsp
(
&
batchMeta
Rsp
);
tFreeS
STbHbRsp
(
&
hb
Rsp
);
terrno
=
TSDB_CODE_INVALID_MSG
;
terrno
=
TSDB_CODE_INVALID_MSG
;
return
-
1
;
return
-
1
;
}
}
void
*
pRsp
=
taosMemoryMalloc
(
rspLen
);
void
*
pRsp
=
taosMemoryMalloc
(
rspLen
);
if
(
pRsp
==
NULL
)
{
if
(
pRsp
==
NULL
)
{
tFreeS
TableMetaBatchRsp
(
&
batchMeta
Rsp
);
tFreeS
STbHbRsp
(
&
hb
Rsp
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
return
-
1
;
}
}
tSerializeS
TableMetaBatchRsp
(
pRsp
,
rspLen
,
&
batchMeta
Rsp
);
tSerializeS
STbHbRsp
(
pRsp
,
rspLen
,
&
hb
Rsp
);
tFreeS
TableMetaBatchRsp
(
&
batchMeta
Rsp
);
tFreeS
STbHbRsp
(
&
hb
Rsp
);
*
ppRsp
=
pRsp
;
*
ppRsp
=
pRsp
;
*
pRspLen
=
rspLen
;
*
pRspLen
=
rspLen
;
return
0
;
return
0
;
...
...
source/libs/catalog/inc/catalogInt.h
浏览文件 @
2861534a
...
@@ -57,6 +57,8 @@ enum {
...
@@ -57,6 +57,8 @@ enum {
CTG_OP_DROP_TB_META
,
CTG_OP_DROP_TB_META
,
CTG_OP_UPDATE_USER
,
CTG_OP_UPDATE_USER
,
CTG_OP_UPDATE_VG_EPSET
,
CTG_OP_UPDATE_VG_EPSET
,
CTG_OP_UPDATE_TB_INDEX
,
CTG_OP_DROP_TB_INDEX
,
CTG_OP_MAX
CTG_OP_MAX
};
};
...
@@ -128,25 +130,33 @@ typedef struct SCtgUserCtx {
...
@@ -128,25 +130,33 @@ typedef struct SCtgUserCtx {
SUserAuthInfo
user
;
SUserAuthInfo
user
;
}
SCtgUserCtx
;
}
SCtgUserCtx
;
typedef
struct
SCtgTbMetaCache
{
typedef
STableIndexRsp
STableIndex
;
SRWLatch
stbLock
;
SRWLatch
metaLock
;
// RC between cache destroy and all other operations
SHashObj
*
metaCache
;
//key:tbname, value:STableMeta
SHashObj
*
stbCache
;
//key:suid, value:STableMeta*
}
SCtgTbMetaCache
;
typedef
struct
SCtgDBCache
{
typedef
struct
SCtgTbCache
{
SRWLatch
metaLock
;
STableMeta
*
pMeta
;
SRWLatch
indexLock
;
STableIndex
*
pIndex
;
}
SCtgTbCache
;
typedef
struct
SCtgVgCache
{
SRWLatch
vgLock
;
SRWLatch
vgLock
;
SDBVgInfo
*
vgInfo
;
}
SCtgVgCache
;
typedef
struct
SCtgDBCache
{
SRWLatch
dbLock
;
// RC between destroy tbCache/stbCache and all reads
uint64_t
dbId
;
uint64_t
dbId
;
int8_t
deleted
;
int8_t
deleted
;
SDBVgInfo
*
vgInfo
;
SCtgVgCache
vgCache
;
SCtgTbMetaCache
tbCache
;
SHashObj
*
tbCache
;
// key:tbname, value:SCtgTbCache
SHashObj
*
stbCache
;
// key:suid, value:STableMeta*
}
SCtgDBCache
;
}
SCtgDBCache
;
typedef
struct
SCtgRentSlot
{
typedef
struct
SCtgRentSlot
{
SRWLatch
lock
;
SRWLatch
lock
;
bool
needSort
;
bool
needSort
;
SArray
*
meta
;
// element is SDbVgVersion or SSTable
Meta
Version
SArray
*
meta
;
// element is SDbVgVersion or SSTableVersion
}
SCtgRentSlot
;
}
SCtgRentSlot
;
typedef
struct
SCtgRentMgmt
{
typedef
struct
SCtgRentMgmt
{
...
@@ -245,8 +255,10 @@ typedef struct SCtgCacheStat {
...
@@ -245,8 +255,10 @@ typedef struct SCtgCacheStat {
uint64_t
userNum
;
uint64_t
userNum
;
uint64_t
vgHitNum
;
uint64_t
vgHitNum
;
uint64_t
vgMissNum
;
uint64_t
vgMissNum
;
uint64_t
tblHitNum
;
uint64_t
tbMetaHitNum
;
uint64_t
tblMissNum
;
uint64_t
tbMetaMissNum
;
uint64_t
tbIndexHitNum
;
uint64_t
tbIndexMissNum
;
uint64_t
userHitNum
;
uint64_t
userHitNum
;
uint64_t
userMissNum
;
uint64_t
userMissNum
;
}
SCtgCacheStat
;
}
SCtgCacheStat
;
...
@@ -268,10 +280,10 @@ typedef struct SCtgUpdateVgMsg {
...
@@ -268,10 +280,10 @@ typedef struct SCtgUpdateVgMsg {
SDBVgInfo
*
dbInfo
;
SDBVgInfo
*
dbInfo
;
}
SCtgUpdateVgMsg
;
}
SCtgUpdateVgMsg
;
typedef
struct
SCtgUpdateTb
l
Msg
{
typedef
struct
SCtgUpdateTb
Meta
Msg
{
SCatalog
*
pCtg
;
SCatalog
*
pCtg
;
STableMetaOutput
*
output
;
STableMetaOutput
*
pMeta
;
}
SCtgUpdateTb
l
Msg
;
}
SCtgUpdateTb
Meta
Msg
;
typedef
struct
SCtgDropDBMsg
{
typedef
struct
SCtgDropDBMsg
{
SCatalog
*
pCtg
;
SCatalog
*
pCtg
;
...
@@ -305,6 +317,17 @@ typedef struct SCtgUpdateUserMsg {
...
@@ -305,6 +317,17 @@ typedef struct SCtgUpdateUserMsg {
SGetUserAuthRsp
userAuth
;
SGetUserAuthRsp
userAuth
;
}
SCtgUpdateUserMsg
;
}
SCtgUpdateUserMsg
;
typedef
struct
SCtgUpdateTbIndexMsg
{
SCatalog
*
pCtg
;
STableIndex
*
pIndex
;
}
SCtgUpdateTbIndexMsg
;
typedef
struct
SCtgDropTbIndexMsg
{
SCatalog
*
pCtg
;
char
dbFName
[
TSDB_DB_FNAME_LEN
];
char
tbName
[
TSDB_TABLE_NAME_LEN
];
}
SCtgDropTbIndexMsg
;
typedef
struct
SCtgUpdateEpsetMsg
{
typedef
struct
SCtgUpdateEpsetMsg
{
SCatalog
*
pCtg
;
SCatalog
*
pCtg
;
char
dbFName
[
TSDB_DB_FNAME_LEN
];
char
dbFName
[
TSDB_DB_FNAME_LEN
];
...
@@ -465,12 +488,11 @@ int32_t ctgOpUpdateUser(SCtgCacheOperation *action);
...
@@ -465,12 +488,11 @@ int32_t ctgOpUpdateUser(SCtgCacheOperation *action);
int32_t
ctgOpUpdateEpset
(
SCtgCacheOperation
*
operation
);
int32_t
ctgOpUpdateEpset
(
SCtgCacheOperation
*
operation
);
int32_t
ctgAcquireVgInfoFromCache
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
SCtgDBCache
**
pCache
);
int32_t
ctgAcquireVgInfoFromCache
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
SCtgDBCache
**
pCache
);
void
ctgReleaseDBCache
(
SCatalog
*
pCtg
,
SCtgDBCache
*
dbCache
);
void
ctgReleaseDBCache
(
SCatalog
*
pCtg
,
SCtgDBCache
*
dbCache
);
void
ctgReleaseVgInfo
(
SCtgDBCache
*
dbCache
);
void
ctgRUnlockVgInfo
(
SCtgDBCache
*
dbCache
);
int32_t
ctgAcquireVgInfoFromCache
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
SCtgDBCache
**
pCache
);
int32_t
ctgTbMetaExistInCache
(
SCatalog
*
pCtg
,
char
*
dbFName
,
char
*
tbName
,
int32_t
*
exist
);
int32_t
ctgTbMetaExistInCache
(
SCatalog
*
pCtg
,
char
*
dbFName
,
char
*
tbName
,
int32_t
*
exist
);
int32_t
ctgReadTbMetaFromCache
(
SCatalog
*
pCtg
,
SCtgTbMetaCtx
*
ctx
,
STableMeta
**
pTableMeta
);
int32_t
ctgReadTbMetaFromCache
(
SCatalog
*
pCtg
,
SCtgTbMetaCtx
*
ctx
,
STableMeta
**
pTableMeta
);
int32_t
ctgReadTbVerFromCache
(
SCatalog
*
pCtg
,
const
SName
*
pTableName
,
int32_t
*
sver
,
int32_t
*
tver
,
int32_t
*
tbType
,
uint64_t
*
suid
,
char
*
stbName
);
int32_t
ctgReadTbVerFromCache
(
SCatalog
*
pCtg
,
SName
*
pTableName
,
int32_t
*
sver
,
int32_t
*
tver
,
int32_t
*
tbType
,
uint64_t
*
suid
,
char
*
stbName
);
int32_t
ctgChkAuthFromCache
(
SCatalog
*
pCtg
,
c
onst
char
*
user
,
const
char
*
dbFName
,
AUTH_TYPE
type
,
bool
*
inCache
,
bool
*
pass
);
int32_t
ctgChkAuthFromCache
(
SCatalog
*
pCtg
,
c
har
*
user
,
char
*
dbFName
,
AUTH_TYPE
type
,
bool
*
inCache
,
bool
*
pass
);
int32_t
ctgDropDbCacheEnqueue
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
int64_t
dbId
);
int32_t
ctgDropDbCacheEnqueue
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
int64_t
dbId
);
int32_t
ctgDropDbVgroupEnqueue
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
bool
syncReq
);
int32_t
ctgDropDbVgroupEnqueue
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
bool
syncReq
);
int32_t
ctgDropStbMetaEnqueue
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
int64_t
dbId
,
const
char
*
stbName
,
uint64_t
suid
,
bool
syncReq
);
int32_t
ctgDropStbMetaEnqueue
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
int64_t
dbId
,
const
char
*
stbName
,
uint64_t
suid
,
bool
syncReq
);
...
@@ -479,12 +501,18 @@ int32_t ctgUpdateVgroupEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId
...
@@ -479,12 +501,18 @@ int32_t ctgUpdateVgroupEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId
int32_t
ctgUpdateTbMetaEnqueue
(
SCatalog
*
pCtg
,
STableMetaOutput
*
output
,
bool
syncReq
);
int32_t
ctgUpdateTbMetaEnqueue
(
SCatalog
*
pCtg
,
STableMetaOutput
*
output
,
bool
syncReq
);
int32_t
ctgUpdateUserEnqueue
(
SCatalog
*
pCtg
,
SGetUserAuthRsp
*
pAuth
,
bool
syncReq
);
int32_t
ctgUpdateUserEnqueue
(
SCatalog
*
pCtg
,
SGetUserAuthRsp
*
pAuth
,
bool
syncReq
);
int32_t
ctgUpdateVgEpsetEnqueue
(
SCatalog
*
pCtg
,
char
*
dbFName
,
int32_t
vgId
,
SEpSet
*
pEpSet
);
int32_t
ctgUpdateVgEpsetEnqueue
(
SCatalog
*
pCtg
,
char
*
dbFName
,
int32_t
vgId
,
SEpSet
*
pEpSet
);
int32_t
ctgUpdateTbIndexEnqueue
(
SCatalog
*
pCtg
,
STableIndex
**
pIndex
,
bool
syncOp
);
int32_t
ctgMetaRentInit
(
SCtgRentMgmt
*
mgmt
,
uint32_t
rentSec
,
int8_t
type
);
int32_t
ctgMetaRentInit
(
SCtgRentMgmt
*
mgmt
,
uint32_t
rentSec
,
int8_t
type
);
int32_t
ctgMetaRentAdd
(
SCtgRentMgmt
*
mgmt
,
void
*
meta
,
int64_t
id
,
int32_t
size
);
int32_t
ctgMetaRentAdd
(
SCtgRentMgmt
*
mgmt
,
void
*
meta
,
int64_t
id
,
int32_t
size
);
int32_t
ctgMetaRentGet
(
SCtgRentMgmt
*
mgmt
,
void
**
res
,
uint32_t
*
num
,
int32_t
size
);
int32_t
ctgMetaRentGet
(
SCtgRentMgmt
*
mgmt
,
void
**
res
,
uint32_t
*
num
,
int32_t
size
);
int32_t
ctgUpdateTbMetaToCache
(
SCatalog
*
pCtg
,
STableMetaOutput
*
pOut
,
bool
syncReq
);
int32_t
ctgUpdateTbMetaToCache
(
SCatalog
*
pCtg
,
STableMetaOutput
*
pOut
,
bool
syncReq
);
int32_t
ctgStartUpdateThread
();
int32_t
ctgStartUpdateThread
();
int32_t
ctgRelaunchGetTbMetaTask
(
SCtgTask
*
pTask
);
int32_t
ctgRelaunchGetTbMetaTask
(
SCtgTask
*
pTask
);
void
ctgReleaseVgInfoToCache
(
SCatalog
*
pCtg
,
SCtgDBCache
*
dbCache
);
int32_t
ctgReadTbIndexFromCache
(
SCatalog
*
pCtg
,
SName
*
pTableName
,
SArray
**
pRes
);
int32_t
ctgDropTbIndexEnqueue
(
SCatalog
*
pCtg
,
SName
*
pName
,
bool
syncOp
);
int32_t
ctgOpDropTbIndex
(
SCtgCacheOperation
*
operation
);
int32_t
ctgOpUpdateTbIndex
(
SCtgCacheOperation
*
operation
);
...
@@ -493,7 +521,7 @@ int32_t ctgGetDBVgInfoFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SBuildU
...
@@ -493,7 +521,7 @@ int32_t ctgGetDBVgInfoFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SBuildU
int32_t
ctgGetQnodeListFromMnode
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
SArray
*
out
,
SCtgTask
*
pTask
);
int32_t
ctgGetQnodeListFromMnode
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
SArray
*
out
,
SCtgTask
*
pTask
);
int32_t
ctgGetDBCfgFromMnode
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
const
char
*
dbFName
,
SDbCfgInfo
*
out
,
SCtgTask
*
pTask
);
int32_t
ctgGetDBCfgFromMnode
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
const
char
*
dbFName
,
SDbCfgInfo
*
out
,
SCtgTask
*
pTask
);
int32_t
ctgGetIndexInfoFromMnode
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
const
char
*
indexName
,
SIndexInfo
*
out
,
SCtgTask
*
pTask
);
int32_t
ctgGetIndexInfoFromMnode
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
const
char
*
indexName
,
SIndexInfo
*
out
,
SCtgTask
*
pTask
);
int32_t
ctgGetTbIndexFromMnode
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
SName
*
name
,
SArray
*
*
out
,
SCtgTask
*
pTask
);
int32_t
ctgGetTbIndexFromMnode
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
SName
*
name
,
STableIndex
*
out
,
SCtgTask
*
pTask
);
int32_t
ctgGetUdfInfoFromMnode
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
const
char
*
funcName
,
SFuncInfo
*
out
,
SCtgTask
*
pTask
);
int32_t
ctgGetUdfInfoFromMnode
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
const
char
*
funcName
,
SFuncInfo
*
out
,
SCtgTask
*
pTask
);
int32_t
ctgGetUserDbAuthFromMnode
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
const
char
*
user
,
SGetUserAuthRsp
*
out
,
SCtgTask
*
pTask
);
int32_t
ctgGetUserDbAuthFromMnode
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
const
char
*
user
,
SGetUserAuthRsp
*
out
,
SCtgTask
*
pTask
);
int32_t
ctgGetTbMetaFromMnodeImpl
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
char
*
dbFName
,
char
*
tbName
,
STableMetaOutput
*
out
,
SCtgTask
*
pTask
);
int32_t
ctgGetTbMetaFromMnodeImpl
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
char
*
dbFName
,
char
*
tbName
,
STableMetaOutput
*
out
,
SCtgTask
*
pTask
);
...
@@ -521,6 +549,8 @@ void ctgFreeSTableMetaOutput(STableMetaOutput* pOutput);
...
@@ -521,6 +549,8 @@ void ctgFreeSTableMetaOutput(STableMetaOutput* pOutput);
int32_t
ctgUpdateMsgCtx
(
SCtgMsgCtx
*
pCtx
,
int32_t
reqType
,
void
*
out
,
char
*
target
);
int32_t
ctgUpdateMsgCtx
(
SCtgMsgCtx
*
pCtx
,
int32_t
reqType
,
void
*
out
,
char
*
target
);
char
*
ctgTaskTypeStr
(
CTG_TASK_TYPE
type
);
char
*
ctgTaskTypeStr
(
CTG_TASK_TYPE
type
);
int32_t
ctgUpdateSendTargetInfo
(
SMsgSendInfo
*
pMsgSendInfo
,
int32_t
msgType
,
SCtgTask
*
pTask
);
int32_t
ctgUpdateSendTargetInfo
(
SMsgSendInfo
*
pMsgSendInfo
,
int32_t
msgType
,
SCtgTask
*
pTask
);
int32_t
ctgCloneTableIndex
(
SArray
*
pIndex
,
SArray
**
pRes
);
void
ctgFreeSTableIndex
(
void
*
info
);
extern
SCatalogMgmt
gCtgMgmt
;
extern
SCatalogMgmt
gCtgMgmt
;
...
...
source/libs/catalog/src/catalog.c
浏览文件 @
2861534a
...
@@ -96,8 +96,7 @@ int32_t ctgRefreshDBVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, const char*
...
@@ -96,8 +96,7 @@ int32_t ctgRefreshDBVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, const char*
if
(
NULL
!=
dbCache
)
{
if
(
NULL
!=
dbCache
)
{
input
.
dbId
=
dbCache
->
dbId
;
input
.
dbId
=
dbCache
->
dbId
;
ctgReleaseVgInfo
(
dbCache
);
ctgReleaseVgInfoToCache
(
pCtg
,
dbCache
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
}
}
input
.
vgVersion
=
CTG_DEFAULT_INVALID_VERSION
;
input
.
vgVersion
=
CTG_DEFAULT_INVALID_VERSION
;
...
@@ -350,7 +349,7 @@ int32_t ctgChkAuth(SCatalog* pCtg, SRequestConnInfo *pConn, const char* user, co
...
@@ -350,7 +349,7 @@ int32_t ctgChkAuth(SCatalog* pCtg, SRequestConnInfo *pConn, const char* user, co
*
pass
=
false
;
*
pass
=
false
;
CTG_ERR_RET
(
ctgChkAuthFromCache
(
pCtg
,
user
,
dbFName
,
type
,
&
inCache
,
pass
));
CTG_ERR_RET
(
ctgChkAuthFromCache
(
pCtg
,
(
char
*
)
user
,
(
char
*
)
dbFName
,
type
,
&
inCache
,
pass
));
if
(
inCache
)
{
if
(
inCache
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -382,6 +381,45 @@ _return:
...
@@ -382,6 +381,45 @@ _return:
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
ctgGetTbIndex
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
SName
*
pTableName
,
SArray
**
pRes
)
{
CTG_ERR_RET
(
ctgReadTbIndexFromCache
(
pCtg
,
pTableName
,
pRes
));
if
(
*
pRes
)
{
return
TSDB_CODE_SUCCESS
;
}
STableIndex
*
pIndex
=
taosMemoryCalloc
(
1
,
sizeof
(
STableIndex
));
if
(
NULL
==
pIndex
)
{
CTG_ERR_RET
(
TSDB_CODE_OUT_OF_MEMORY
);
}
int32_t
code
=
ctgGetTbIndexFromMnode
(
pCtg
,
pConn
,
(
SName
*
)
pTableName
,
pIndex
,
NULL
);
if
(
TSDB_CODE_MND_DB_INDEX_NOT_EXIST
==
code
)
{
code
=
0
;
goto
_return
;
}
CTG_ERR_JRET
(
code
);
SArray
*
pInfo
=
NULL
;
CTG_ERR_JRET
(
ctgCloneTableIndex
(
pIndex
->
pIndex
,
&
pInfo
));
*
pRes
=
pInfo
;
CTG_ERR_JRET
(
ctgUpdateTbIndexEnqueue
(
pCtg
,
&
pIndex
,
false
));
return
TSDB_CODE_SUCCESS
;
_return:
tFreeSTableIndexRsp
(
pIndex
);
taosMemoryFree
(
pIndex
);
taosArrayDestroyEx
(
*
pRes
,
tFreeSTableIndexInfo
);
*
pRes
=
NULL
;
CTG_RET
(
code
);
}
int32_t
ctgGetTbDistVgInfo
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
SName
*
pTableName
,
SArray
**
pVgList
)
{
int32_t
ctgGetTbDistVgInfo
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
SName
*
pTableName
,
SArray
**
pVgList
)
{
STableMeta
*
tbMeta
=
NULL
;
STableMeta
*
tbMeta
=
NULL
;
int32_t
code
=
0
;
int32_t
code
=
0
;
...
@@ -404,7 +442,7 @@ int32_t ctgGetTbDistVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, SName* pTabl
...
@@ -404,7 +442,7 @@ int32_t ctgGetTbDistVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, SName* pTabl
CTG_ERR_JRET
(
ctgGetDBVgInfo
(
pCtg
,
pConn
,
db
,
&
dbCache
,
&
vgInfo
));
CTG_ERR_JRET
(
ctgGetDBVgInfo
(
pCtg
,
pConn
,
db
,
&
dbCache
,
&
vgInfo
));
if
(
dbCache
)
{
if
(
dbCache
)
{
vgHash
=
dbCache
->
vgInfo
->
vgHash
;
vgHash
=
dbCache
->
vg
Cache
.
vg
Info
->
vgHash
;
}
else
{
}
else
{
vgHash
=
vgInfo
->
vgHash
;
vgHash
=
vgInfo
->
vgHash
;
}
}
...
@@ -442,7 +480,7 @@ int32_t ctgGetTbDistVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, SName* pTabl
...
@@ -442,7 +480,7 @@ int32_t ctgGetTbDistVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, SName* pTabl
_return:
_return:
if
(
dbCache
)
{
if
(
dbCache
)
{
ctgR
elease
VgInfo
(
dbCache
);
ctgR
Unlock
VgInfo
(
dbCache
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
}
}
...
@@ -631,12 +669,11 @@ int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* vers
...
@@ -631,12 +669,11 @@ int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* vers
CTG_API_LEAVE
(
TSDB_CODE_SUCCESS
);
CTG_API_LEAVE
(
TSDB_CODE_SUCCESS
);
}
}
*
version
=
dbCache
->
vgInfo
->
vgVersion
;
*
version
=
dbCache
->
vg
Cache
.
vg
Info
->
vgVersion
;
*
dbId
=
dbCache
->
dbId
;
*
dbId
=
dbCache
->
dbId
;
*
tableNum
=
dbCache
->
vgInfo
->
numOfTable
;
*
tableNum
=
dbCache
->
vg
Cache
.
vg
Info
->
numOfTable
;
ctgReleaseVgInfo
(
dbCache
);
ctgReleaseVgInfoToCache
(
pCtg
,
dbCache
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
ctgDebug
(
"Got db vgVersion from cache, dbFName:%s, vgVersion:%d"
,
dbFName
,
*
version
);
ctgDebug
(
"Got db vgVersion from cache, dbFName:%s, vgVersion:%d"
,
dbFName
,
*
version
);
...
@@ -661,7 +698,7 @@ int32_t catalogGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, const char*
...
@@ -661,7 +698,7 @@ int32_t catalogGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, const char*
SDBVgInfo
*
vgInfo
=
NULL
;
SDBVgInfo
*
vgInfo
=
NULL
;
CTG_ERR_JRET
(
ctgGetDBVgInfo
(
pCtg
,
pConn
,
dbFName
,
&
dbCache
,
&
vgInfo
));
CTG_ERR_JRET
(
ctgGetDBVgInfo
(
pCtg
,
pConn
,
dbFName
,
&
dbCache
,
&
vgInfo
));
if
(
dbCache
)
{
if
(
dbCache
)
{
vgHash
=
dbCache
->
vgInfo
->
vgHash
;
vgHash
=
dbCache
->
vg
Cache
.
vg
Info
->
vgHash
;
}
else
{
}
else
{
vgHash
=
vgInfo
->
vgHash
;
vgHash
=
vgInfo
->
vgHash
;
}
}
...
@@ -674,7 +711,7 @@ int32_t catalogGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, const char*
...
@@ -674,7 +711,7 @@ int32_t catalogGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, const char*
_return:
_return:
if
(
dbCache
)
{
if
(
dbCache
)
{
ctgR
elease
VgInfo
(
dbCache
);
ctgR
Unlock
VgInfo
(
dbCache
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
}
}
...
@@ -741,6 +778,30 @@ _return:
...
@@ -741,6 +778,30 @@ _return:
CTG_API_LEAVE
(
code
);
CTG_API_LEAVE
(
code
);
}
}
int32_t
catalogUpdateTableIndex
(
SCatalog
*
pCtg
,
STableIndexRsp
*
pRsp
)
{
CTG_API_ENTER
();
int32_t
code
=
0
;
if
(
NULL
==
pCtg
||
NULL
==
pRsp
)
{
CTG_API_LEAVE
(
TSDB_CODE_CTG_INVALID_INPUT
);
}
STableIndex
*
pIndex
=
taosMemoryCalloc
(
1
,
sizeof
(
STableIndex
));
if
(
NULL
==
pIndex
)
{
CTG_API_LEAVE
(
TSDB_CODE_OUT_OF_MEMORY
);
}
memcpy
(
pIndex
,
pRsp
,
sizeof
(
STableIndex
));
CTG_ERR_JRET
(
ctgUpdateTbIndexEnqueue
(
pCtg
,
&
pIndex
,
false
));
_return:
CTG_API_LEAVE
(
code
);
}
int32_t
catalogRemoveTableMeta
(
SCatalog
*
pCtg
,
SName
*
pTableName
)
{
int32_t
catalogRemoveTableMeta
(
SCatalog
*
pCtg
,
SName
*
pTableName
)
{
CTG_API_ENTER
();
CTG_API_ENTER
();
...
@@ -932,12 +993,12 @@ int32_t catalogGetTableHashVgroup(SCatalog *pCtg, SRequestConnInfo *pConn, const
...
@@ -932,12 +993,12 @@ int32_t catalogGetTableHashVgroup(SCatalog *pCtg, SRequestConnInfo *pConn, const
SDBVgInfo
*
vgInfo
=
NULL
;
SDBVgInfo
*
vgInfo
=
NULL
;
CTG_ERR_JRET
(
ctgGetDBVgInfo
(
pCtg
,
pConn
,
db
,
&
dbCache
,
&
vgInfo
));
CTG_ERR_JRET
(
ctgGetDBVgInfo
(
pCtg
,
pConn
,
db
,
&
dbCache
,
&
vgInfo
));
CTG_ERR_JRET
(
ctgGetVgInfoFromHashValue
(
pCtg
,
vgInfo
?
vgInfo
:
dbCache
->
vgInfo
,
pTableName
,
pVgroup
));
CTG_ERR_JRET
(
ctgGetVgInfoFromHashValue
(
pCtg
,
vgInfo
?
vgInfo
:
dbCache
->
vg
Cache
.
vg
Info
,
pTableName
,
pVgroup
));
_return:
_return:
if
(
dbCache
)
{
if
(
dbCache
)
{
ctgR
elease
VgInfo
(
dbCache
);
ctgR
Unlock
VgInfo
(
dbCache
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
}
}
...
@@ -1060,14 +1121,14 @@ _return:
...
@@ -1060,14 +1121,14 @@ _return:
CTG_API_LEAVE
(
TSDB_CODE_SUCCESS
);
CTG_API_LEAVE
(
TSDB_CODE_SUCCESS
);
}
}
int32_t
catalogGetExpiredSTables
(
SCatalog
*
pCtg
,
SSTable
MetaVersion
**
stables
,
uint32_t
*
num
)
{
int32_t
catalogGetExpiredSTables
(
SCatalog
*
pCtg
,
SSTable
Version
**
stables
,
uint32_t
*
num
)
{
CTG_API_ENTER
();
CTG_API_ENTER
();
if
(
NULL
==
pCtg
||
NULL
==
stables
||
NULL
==
num
)
{
if
(
NULL
==
pCtg
||
NULL
==
stables
||
NULL
==
num
)
{
CTG_API_LEAVE
(
TSDB_CODE_CTG_INVALID_INPUT
);
CTG_API_LEAVE
(
TSDB_CODE_CTG_INVALID_INPUT
);
}
}
CTG_API_LEAVE
(
ctgMetaRentGet
(
&
pCtg
->
stbRent
,
(
void
**
)
stables
,
num
,
sizeof
(
SSTableMeta
Version
)));
CTG_API_LEAVE
(
ctgMetaRentGet
(
&
pCtg
->
stbRent
,
(
void
**
)
stables
,
num
,
sizeof
(
SSTable
Version
)));
}
}
int32_t
catalogGetExpiredDBs
(
SCatalog
*
pCtg
,
SDbVgVersion
**
dbs
,
uint32_t
*
num
)
{
int32_t
catalogGetExpiredDBs
(
SCatalog
*
pCtg
,
SDbVgVersion
**
dbs
,
uint32_t
*
num
)
{
...
@@ -1138,7 +1199,12 @@ int32_t catalogGetTableIndex(SCatalog* pCtg, SRequestConnInfo *pConn, const SNam
...
@@ -1138,7 +1199,12 @@ int32_t catalogGetTableIndex(SCatalog* pCtg, SRequestConnInfo *pConn, const SNam
CTG_API_LEAVE
(
TSDB_CODE_CTG_INVALID_INPUT
);
CTG_API_LEAVE
(
TSDB_CODE_CTG_INVALID_INPUT
);
}
}
CTG_API_LEAVE
(
ctgGetTbIndexFromMnode
(
pCtg
,
pConn
,
(
SName
*
)
pTableName
,
pRes
,
NULL
));
int32_t
code
=
0
;
CTG_ERR_JRET
(
ctgGetTbIndex
(
pCtg
,
pConn
,
(
SName
*
)
pTableName
,
pRes
));
_return:
CTG_API_LEAVE
(
code
);
}
}
int32_t
catalogGetUdfInfo
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
const
char
*
funcName
,
SFuncInfo
*
pInfo
)
{
int32_t
catalogGetUdfInfo
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
const
char
*
funcName
,
SFuncInfo
*
pInfo
)
{
...
...
source/libs/catalog/src/ctgAsync.c
浏览文件 @
2861534a
...
@@ -344,6 +344,11 @@ int32_t ctgHandleForceUpdate(SCatalog* pCtg, SCtgJob *pJob, const SCatalogReq* p
...
@@ -344,6 +344,11 @@ int32_t ctgHandleForceUpdate(SCatalog* pCtg, SCtgJob *pJob, const SCatalogReq* p
}
}
}
}
for
(
int32_t
i
=
0
;
i
<
pJob
->
tbIndexNum
;
++
i
)
{
SName
*
name
=
taosArrayGet
(
pReq
->
pTableIndex
,
i
);
ctgDropTbIndexEnqueue
(
pCtg
,
name
,
true
);
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -680,15 +685,14 @@ int32_t ctgHandleGetTbMetaRsp(SCtgTask* pTask, int32_t reqType, const SDataBuf *
...
@@ -680,15 +685,14 @@ int32_t ctgHandleGetTbMetaRsp(SCtgTask* pTask, int32_t reqType, const SDataBuf *
CTG_ERR_RET
(
ctgAcquireVgInfoFromCache
(
pCtg
,
dbFName
,
&
dbCache
));
CTG_ERR_RET
(
ctgAcquireVgInfoFromCache
(
pCtg
,
dbFName
,
&
dbCache
));
if
(
NULL
!=
dbCache
)
{
if
(
NULL
!=
dbCache
)
{
SVgroupInfo
vgInfo
=
{
0
};
SVgroupInfo
vgInfo
=
{
0
};
CTG_ERR_JRET
(
ctgGetVgInfoFromHashValue
(
pCtg
,
dbCache
->
vgInfo
,
ctx
->
pName
,
&
vgInfo
));
CTG_ERR_JRET
(
ctgGetVgInfoFromHashValue
(
pCtg
,
dbCache
->
vg
Cache
.
vg
Info
,
ctx
->
pName
,
&
vgInfo
));
ctgDebug
(
"will refresh tbmeta, not supposed to be stb, tbName:%s, flag:%d"
,
tNameGetTableName
(
ctx
->
pName
),
ctx
->
flag
);
ctgDebug
(
"will refresh tbmeta, not supposed to be stb, tbName:%s, flag:%d"
,
tNameGetTableName
(
ctx
->
pName
),
ctx
->
flag
);
ctx
->
vgId
=
vgInfo
.
vgId
;
ctx
->
vgId
=
vgInfo
.
vgId
;
CTG_ERR_JRET
(
ctgGetTbMetaFromVnode
(
pCtg
,
pConn
,
ctx
->
pName
,
&
vgInfo
,
NULL
,
pTask
));
CTG_ERR_JRET
(
ctgGetTbMetaFromVnode
(
pCtg
,
pConn
,
ctx
->
pName
,
&
vgInfo
,
NULL
,
pTask
));
ctgReleaseVgInfo
(
dbCache
);
ctgReleaseVgInfoToCache
(
pCtg
,
dbCache
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
}
else
{
}
else
{
SBuildUseDBInput
input
=
{
0
};
SBuildUseDBInput
input
=
{
0
};
...
@@ -786,7 +790,7 @@ int32_t ctgHandleGetTbMetaRsp(SCtgTask* pTask, int32_t reqType, const SDataBuf *
...
@@ -786,7 +790,7 @@ int32_t ctgHandleGetTbMetaRsp(SCtgTask* pTask, int32_t reqType, const SDataBuf *
_return:
_return:
if
(
dbCache
)
{
if
(
dbCache
)
{
ctgR
elease
VgInfo
(
dbCache
);
ctgR
Unlock
VgInfo
(
dbCache
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
}
}
...
@@ -866,9 +870,15 @@ _return:
...
@@ -866,9 +870,15 @@ _return:
int32_t
ctgHandleGetTbIndexRsp
(
SCtgTask
*
pTask
,
int32_t
reqType
,
const
SDataBuf
*
pMsg
,
int32_t
rspCode
)
{
int32_t
ctgHandleGetTbIndexRsp
(
SCtgTask
*
pTask
,
int32_t
reqType
,
const
SDataBuf
*
pMsg
,
int32_t
rspCode
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
CTG_ERR_JRET
(
ctgProcessRspMsg
(
pTask
->
msgCtx
.
out
,
reqType
,
pMsg
->
pData
,
pMsg
->
len
,
rspCode
,
pTask
->
msgCtx
.
target
));
CTG_ERR_JRET
(
ctgProcessRspMsg
(
&
pTask
->
msgCtx
.
out
,
reqType
,
pMsg
->
pData
,
pMsg
->
len
,
rspCode
,
pTask
->
msgCtx
.
target
));
TSWAP
(
pTask
->
res
,
pTask
->
msgCtx
.
out
);
STableIndex
*
pOut
=
(
STableIndex
*
)
pTask
->
msgCtx
.
out
;
SArray
*
pInfo
=
NULL
;
CTG_ERR_JRET
(
ctgCloneTableIndex
(
pOut
->
pIndex
,
&
pInfo
));
pTask
->
res
=
pInfo
;
SCtgTbIndexCtx
*
ctx
=
pTask
->
taskCtx
;
CTG_ERR_JRET
(
ctgUpdateTbIndexEnqueue
(
pTask
->
pJob
->
pCtg
,
(
STableIndex
**
)
&
pTask
->
msgCtx
.
out
,
false
));
_return:
_return:
if
(
TSDB_CODE_MND_DB_INDEX_NOT_EXIST
==
code
)
{
if
(
TSDB_CODE_MND_DB_INDEX_NOT_EXIST
==
code
)
{
...
@@ -1008,7 +1018,7 @@ int32_t ctgAsyncRefreshTbMeta(SCtgTask *pTask) {
...
@@ -1008,7 +1018,7 @@ int32_t ctgAsyncRefreshTbMeta(SCtgTask *pTask) {
CTG_ERR_RET
(
ctgAcquireVgInfoFromCache
(
pCtg
,
dbFName
,
&
dbCache
));
CTG_ERR_RET
(
ctgAcquireVgInfoFromCache
(
pCtg
,
dbFName
,
&
dbCache
));
if
(
dbCache
)
{
if
(
dbCache
)
{
SVgroupInfo
vgInfo
=
{
0
};
SVgroupInfo
vgInfo
=
{
0
};
CTG_ERR_RET
(
ctgGetVgInfoFromHashValue
(
pCtg
,
dbCache
->
vgInfo
,
ctx
->
pName
,
&
vgInfo
));
CTG_ERR_RET
(
ctgGetVgInfoFromHashValue
(
pCtg
,
dbCache
->
vg
Cache
.
vg
Info
,
ctx
->
pName
,
&
vgInfo
));
ctgDebug
(
"will refresh tbmeta, not supposed to be stb, tbName:%s, flag:%d"
,
tNameGetTableName
(
ctx
->
pName
),
ctx
->
flag
);
ctgDebug
(
"will refresh tbmeta, not supposed to be stb, tbName:%s, flag:%d"
,
tNameGetTableName
(
ctx
->
pName
),
ctx
->
flag
);
...
@@ -1026,8 +1036,7 @@ int32_t ctgAsyncRefreshTbMeta(SCtgTask *pTask) {
...
@@ -1026,8 +1036,7 @@ int32_t ctgAsyncRefreshTbMeta(SCtgTask *pTask) {
_return:
_return:
if
(
dbCache
)
{
if
(
dbCache
)
{
ctgReleaseVgInfo
(
dbCache
);
ctgReleaseVgInfoToCache
(
pCtg
,
dbCache
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
}
}
CTG_RET
(
code
);
CTG_RET
(
code
);
...
@@ -1057,7 +1066,7 @@ int32_t ctgLaunchGetDbVgTask(SCtgTask *pTask) {
...
@@ -1057,7 +1066,7 @@ int32_t ctgLaunchGetDbVgTask(SCtgTask *pTask) {
CTG_ERR_RET
(
ctgAcquireVgInfoFromCache
(
pCtg
,
pCtx
->
dbFName
,
&
dbCache
));
CTG_ERR_RET
(
ctgAcquireVgInfoFromCache
(
pCtg
,
pCtx
->
dbFName
,
&
dbCache
));
if
(
NULL
!=
dbCache
)
{
if
(
NULL
!=
dbCache
)
{
CTG_ERR_JRET
(
ctgGenerateVgList
(
pCtg
,
dbCache
->
vgInfo
->
vgHash
,
(
SArray
**
)
&
pTask
->
res
));
CTG_ERR_JRET
(
ctgGenerateVgList
(
pCtg
,
dbCache
->
vg
Cache
.
vg
Info
->
vgHash
,
(
SArray
**
)
&
pTask
->
res
));
CTG_ERR_JRET
(
ctgHandleTaskEnd
(
pTask
,
0
));
CTG_ERR_JRET
(
ctgHandleTaskEnd
(
pTask
,
0
));
}
else
{
}
else
{
...
@@ -1072,8 +1081,7 @@ int32_t ctgLaunchGetDbVgTask(SCtgTask *pTask) {
...
@@ -1072,8 +1081,7 @@ int32_t ctgLaunchGetDbVgTask(SCtgTask *pTask) {
_return:
_return:
if
(
dbCache
)
{
if
(
dbCache
)
{
ctgReleaseVgInfo
(
dbCache
);
ctgReleaseVgInfoToCache
(
pCtg
,
dbCache
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
}
}
CTG_RET
(
code
);
CTG_RET
(
code
);
...
@@ -1092,7 +1100,7 @@ int32_t ctgLaunchGetTbHashTask(SCtgTask *pTask) {
...
@@ -1092,7 +1100,7 @@ int32_t ctgLaunchGetTbHashTask(SCtgTask *pTask) {
if
(
NULL
==
pTask
->
res
)
{
if
(
NULL
==
pTask
->
res
)
{
CTG_ERR_JRET
(
TSDB_CODE_OUT_OF_MEMORY
);
CTG_ERR_JRET
(
TSDB_CODE_OUT_OF_MEMORY
);
}
}
CTG_ERR_JRET
(
ctgGetVgInfoFromHashValue
(
pCtg
,
dbCache
->
vgInfo
,
pCtx
->
pName
,
(
SVgroupInfo
*
)
pTask
->
res
));
CTG_ERR_JRET
(
ctgGetVgInfoFromHashValue
(
pCtg
,
dbCache
->
vg
Cache
.
vg
Info
,
pCtx
->
pName
,
(
SVgroupInfo
*
)
pTask
->
res
));
CTG_ERR_JRET
(
ctgHandleTaskEnd
(
pTask
,
0
));
CTG_ERR_JRET
(
ctgHandleTaskEnd
(
pTask
,
0
));
}
else
{
}
else
{
...
@@ -1107,8 +1115,7 @@ int32_t ctgLaunchGetTbHashTask(SCtgTask *pTask) {
...
@@ -1107,8 +1115,7 @@ int32_t ctgLaunchGetTbHashTask(SCtgTask *pTask) {
_return:
_return:
if
(
dbCache
)
{
if
(
dbCache
)
{
ctgReleaseVgInfo
(
dbCache
);
ctgReleaseVgInfoToCache
(
pCtg
,
dbCache
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
}
}
CTG_RET
(
code
);
CTG_RET
(
code
);
...
@@ -1119,6 +1126,15 @@ int32_t ctgLaunchGetTbIndexTask(SCtgTask *pTask) {
...
@@ -1119,6 +1126,15 @@ int32_t ctgLaunchGetTbIndexTask(SCtgTask *pTask) {
SCatalog
*
pCtg
=
pTask
->
pJob
->
pCtg
;
SCatalog
*
pCtg
=
pTask
->
pJob
->
pCtg
;
SRequestConnInfo
*
pConn
=
&
pTask
->
pJob
->
conn
;
SRequestConnInfo
*
pConn
=
&
pTask
->
pJob
->
conn
;
SCtgTbIndexCtx
*
pCtx
=
(
SCtgTbIndexCtx
*
)
pTask
->
taskCtx
;
SCtgTbIndexCtx
*
pCtx
=
(
SCtgTbIndexCtx
*
)
pTask
->
taskCtx
;
SArray
*
pRes
=
NULL
;
CTG_ERR_RET
(
ctgReadTbIndexFromCache
(
pCtg
,
pCtx
->
pName
,
&
pRes
));
if
(
pRes
)
{
pTask
->
res
=
pRes
;
CTG_ERR_RET
(
ctgHandleTaskEnd
(
pTask
,
0
));
return
TSDB_CODE_SUCCESS
;
}
CTG_ERR_RET
(
ctgGetTbIndexFromMnode
(
pCtg
,
pConn
,
pCtx
->
pName
,
NULL
,
pTask
));
CTG_ERR_RET
(
ctgGetTbIndexFromMnode
(
pCtg
,
pConn
,
pCtx
->
pName
,
NULL
,
pTask
));
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -1157,9 +1173,9 @@ int32_t ctgLaunchGetDbInfoTask(SCtgTask *pTask) {
...
@@ -1157,9 +1173,9 @@ int32_t ctgLaunchGetDbInfoTask(SCtgTask *pTask) {
SDbInfo
*
pInfo
=
(
SDbInfo
*
)
pTask
->
res
;
SDbInfo
*
pInfo
=
(
SDbInfo
*
)
pTask
->
res
;
CTG_ERR_RET
(
ctgAcquireVgInfoFromCache
(
pCtg
,
pCtx
->
dbFName
,
&
dbCache
));
CTG_ERR_RET
(
ctgAcquireVgInfoFromCache
(
pCtg
,
pCtx
->
dbFName
,
&
dbCache
));
if
(
NULL
!=
dbCache
)
{
if
(
NULL
!=
dbCache
)
{
pInfo
->
vgVer
=
dbCache
->
vgInfo
->
vgVersion
;
pInfo
->
vgVer
=
dbCache
->
vg
Cache
.
vg
Info
->
vgVersion
;
pInfo
->
dbId
=
dbCache
->
dbId
;
pInfo
->
dbId
=
dbCache
->
dbId
;
pInfo
->
tbNum
=
dbCache
->
vgInfo
->
numOfTable
;
pInfo
->
tbNum
=
dbCache
->
vg
Cache
.
vg
Info
->
numOfTable
;
}
else
{
}
else
{
pInfo
->
vgVer
=
CTG_DEFAULT_INVALID_VERSION
;
pInfo
->
vgVer
=
CTG_DEFAULT_INVALID_VERSION
;
}
}
...
@@ -1169,8 +1185,7 @@ int32_t ctgLaunchGetDbInfoTask(SCtgTask *pTask) {
...
@@ -1169,8 +1185,7 @@ int32_t ctgLaunchGetDbInfoTask(SCtgTask *pTask) {
_return:
_return:
if
(
dbCache
)
{
if
(
dbCache
)
{
ctgReleaseVgInfo
(
dbCache
);
ctgReleaseVgInfoToCache
(
pCtg
,
dbCache
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
}
}
CTG_RET
(
code
);
CTG_RET
(
code
);
...
...
source/libs/catalog/src/ctgCache.c
浏览文件 @
2861534a
...
@@ -59,18 +59,27 @@ SCtgOperation gCtgCacheOperation[CTG_OP_MAX] = {
...
@@ -59,18 +59,27 @@ SCtgOperation gCtgCacheOperation[CTG_OP_MAX] = {
CTG_OP_UPDATE_VG_EPSET
,
CTG_OP_UPDATE_VG_EPSET
,
"update epset"
,
"update epset"
,
ctgOpUpdateEpset
ctgOpUpdateEpset
},
{
CTG_OP_UPDATE_TB_INDEX
,
"update tbIndex"
,
ctgOpUpdateTbIndex
},
{
CTG_OP_DROP_TB_INDEX
,
"drop tbIndex"
,
ctgOpDropTbIndex
}
}
};
};
int32_t
ctg
Acquire
VgInfo
(
SCatalog
*
pCtg
,
SCtgDBCache
*
dbCache
,
bool
*
inCache
)
{
int32_t
ctg
RLock
VgInfo
(
SCatalog
*
pCtg
,
SCtgDBCache
*
dbCache
,
bool
*
inCache
)
{
CTG_LOCK
(
CTG_READ
,
&
dbCache
->
vgLock
);
CTG_LOCK
(
CTG_READ
,
&
dbCache
->
vg
Cache
.
vg
Lock
);
if
(
dbCache
->
deleted
)
{
if
(
dbCache
->
deleted
)
{
CTG_UNLOCK
(
CTG_READ
,
&
dbCache
->
vgLock
);
CTG_UNLOCK
(
CTG_READ
,
&
dbCache
->
vg
Cache
.
vg
Lock
);
ctgDebug
(
"db is dropping, dbId:%"
PRIx64
,
dbCache
->
dbId
);
ctgDebug
(
"db is dropping, dbId:%"
PRIx64
,
dbCache
->
dbId
);
...
@@ -79,8 +88,8 @@ int32_t ctgAcquireVgInfo(SCatalog *pCtg, SCtgDBCache *dbCache, bool *inCache) {
...
@@ -79,8 +88,8 @@ int32_t ctgAcquireVgInfo(SCatalog *pCtg, SCtgDBCache *dbCache, bool *inCache) {
}
}
if
(
NULL
==
dbCache
->
vgInfo
)
{
if
(
NULL
==
dbCache
->
vg
Cache
.
vg
Info
)
{
CTG_UNLOCK
(
CTG_READ
,
&
dbCache
->
vgLock
);
CTG_UNLOCK
(
CTG_READ
,
&
dbCache
->
vg
Cache
.
vg
Lock
);
*
inCache
=
false
;
*
inCache
=
false
;
ctgDebug
(
"db vgInfo is empty, dbId:%"
PRIx64
,
dbCache
->
dbId
);
ctgDebug
(
"db vgInfo is empty, dbId:%"
PRIx64
,
dbCache
->
dbId
);
...
@@ -92,50 +101,47 @@ int32_t ctgAcquireVgInfo(SCatalog *pCtg, SCtgDBCache *dbCache, bool *inCache) {
...
@@ -92,50 +101,47 @@ int32_t ctgAcquireVgInfo(SCatalog *pCtg, SCtgDBCache *dbCache, bool *inCache) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
ctgW
Acquire
VgInfo
(
SCatalog
*
pCtg
,
SCtgDBCache
*
dbCache
)
{
int32_t
ctgW
Lock
VgInfo
(
SCatalog
*
pCtg
,
SCtgDBCache
*
dbCache
)
{
CTG_LOCK
(
CTG_WRITE
,
&
dbCache
->
vgLock
);
CTG_LOCK
(
CTG_WRITE
,
&
dbCache
->
vg
Cache
.
vg
Lock
);
if
(
dbCache
->
deleted
)
{
if
(
dbCache
->
deleted
)
{
ctgDebug
(
"db is dropping, dbId:%"
PRIx64
,
dbCache
->
dbId
);
ctgDebug
(
"db is dropping, dbId:%"
PRIx64
,
dbCache
->
dbId
);
CTG_UNLOCK
(
CTG_WRITE
,
&
dbCache
->
vgLock
);
CTG_UNLOCK
(
CTG_WRITE
,
&
dbCache
->
vg
Cache
.
vg
Lock
);
CTG_ERR_RET
(
TSDB_CODE_CTG_DB_DROPPED
);
CTG_ERR_RET
(
TSDB_CODE_CTG_DB_DROPPED
);
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
void
ctgR
eleaseDBCache
(
SCatalog
*
pCtg
,
SCtgDBCache
*
dbCache
)
{
void
ctgR
UnlockVgInfo
(
SCtgDBCache
*
dbCache
)
{
taosHashRelease
(
pCtg
->
dbCache
,
dbCache
);
CTG_UNLOCK
(
CTG_READ
,
&
dbCache
->
vgCache
.
vgLock
);
}
}
void
ctg
Release
VgInfo
(
SCtgDBCache
*
dbCache
)
{
void
ctg
WUnlock
VgInfo
(
SCtgDBCache
*
dbCache
)
{
CTG_UNLOCK
(
CTG_
READ
,
&
dbCache
->
vgLock
);
CTG_UNLOCK
(
CTG_
WRITE
,
&
dbCache
->
vgCache
.
vgLock
);
}
}
void
ctg
WReleaseVgInfo
(
SCtgDBCache
*
dbCache
)
{
void
ctg
ReleaseDBCache
(
SCatalog
*
pCtg
,
SCtgDBCache
*
dbCache
)
{
CTG_UNLOCK
(
CTG_
WRITE
,
&
dbCache
->
vg
Lock
);
CTG_UNLOCK
(
CTG_
READ
,
&
dbCache
->
db
Lock
);
}
}
int32_t
ctgAcquireDBCacheImpl
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
SCtgDBCache
**
pCache
,
bool
acquire
)
{
int32_t
ctgAcquireDBCacheImpl
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
SCtgDBCache
**
pCache
,
bool
acquire
)
{
char
*
p
=
strchr
(
dbFName
,
'.'
);
char
*
p
=
strchr
(
dbFName
,
'.'
);
if
(
p
&&
CTG_IS_SYS_DBNAME
(
p
+
1
))
{
if
(
p
&&
CTG_IS_SYS_DBNAME
(
p
+
1
))
{
dbFName
=
p
+
1
;
dbFName
=
p
+
1
;
}
}
SCtgDBCache
*
dbCache
=
NULL
;
SCtgDBCache
*
dbCache
=
(
SCtgDBCache
*
)
taosHashGet
(
pCtg
->
dbCache
,
dbFName
,
strlen
(
dbFName
));
if
(
acquire
)
{
dbCache
=
(
SCtgDBCache
*
)
taosHashAcquire
(
pCtg
->
dbCache
,
dbFName
,
strlen
(
dbFName
));
}
else
{
dbCache
=
(
SCtgDBCache
*
)
taosHashGet
(
pCtg
->
dbCache
,
dbFName
,
strlen
(
dbFName
));
}
if
(
NULL
==
dbCache
)
{
if
(
NULL
==
dbCache
)
{
*
pCache
=
NULL
;
*
pCache
=
NULL
;
ctgDebug
(
"db not in cache, dbFName:%s"
,
dbFName
);
ctgDebug
(
"db not in cache, dbFName:%s"
,
dbFName
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
if
(
acquire
)
{
CTG_LOCK
(
CTG_READ
,
&
dbCache
->
dbLock
);
}
if
(
dbCache
->
deleted
)
{
if
(
dbCache
->
deleted
)
{
if
(
acquire
)
{
if
(
acquire
)
{
ctgReleaseDBCache
(
pCtg
,
dbCache
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
...
@@ -159,15 +165,35 @@ int32_t ctgGetDBCache(SCatalog* pCtg, const char *dbFName, SCtgDBCache **pCache)
...
@@ -159,15 +165,35 @@ int32_t ctgGetDBCache(SCatalog* pCtg, const char *dbFName, SCtgDBCache **pCache)
CTG_RET
(
ctgAcquireDBCacheImpl
(
pCtg
,
dbFName
,
pCache
,
false
));
CTG_RET
(
ctgAcquireDBCacheImpl
(
pCtg
,
dbFName
,
pCache
,
false
));
}
}
void
ctgReleaseVgInfoToCache
(
SCatalog
*
pCtg
,
SCtgDBCache
*
dbCache
)
{
ctgRUnlockVgInfo
(
dbCache
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
}
int32_t
ctgAcquireVgInfoFromCache
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
SCtgDBCache
**
pCache
)
{
void
ctgReleaseTbMetaToCache
(
SCatalog
*
pCtg
,
SCtgDBCache
*
dbCache
,
SCtgTbCache
*
pCache
)
{
SCtgDBCache
*
dbCache
=
NULL
;
if
(
pCache
)
{
CTG_UNLOCK
(
CTG_READ
,
&
pCache
->
metaLock
);
taosHashRelease
(
dbCache
->
tbCache
,
pCache
);
}
if
(
NULL
==
pCtg
->
dbCache
)
{
if
(
dbCache
)
{
ctgDebug
(
"empty db cache, dbFName:%s"
,
dbFName
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
goto
_return
;
}
}
void
ctgReleaseTbIndexToCache
(
SCatalog
*
pCtg
,
SCtgDBCache
*
dbCache
,
SCtgTbCache
*
pCache
)
{
if
(
pCache
)
{
CTG_UNLOCK
(
CTG_READ
,
&
pCache
->
indexLock
);
taosHashRelease
(
dbCache
->
tbCache
,
pCache
);
}
}
if
(
dbCache
)
{
ctgReleaseDBCache
(
pCtg
,
dbCache
);
}
}
int32_t
ctgAcquireVgInfoFromCache
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
SCtgDBCache
**
pCache
)
{
SCtgDBCache
*
dbCache
=
NULL
;
ctgAcquireDBCache
(
pCtg
,
dbFName
,
&
dbCache
);
ctgAcquireDBCache
(
pCtg
,
dbFName
,
&
dbCache
);
if
(
NULL
==
dbCache
)
{
if
(
NULL
==
dbCache
)
{
ctgDebug
(
"db %s not in cache"
,
dbFName
);
ctgDebug
(
"db %s not in cache"
,
dbFName
);
...
@@ -175,7 +201,7 @@ int32_t ctgAcquireVgInfoFromCache(SCatalog* pCtg, const char *dbFName, SCtgDBCac
...
@@ -175,7 +201,7 @@ int32_t ctgAcquireVgInfoFromCache(SCatalog* pCtg, const char *dbFName, SCtgDBCac
}
}
bool
inCache
=
false
;
bool
inCache
=
false
;
ctg
Acquire
VgInfo
(
pCtg
,
dbCache
,
&
inCache
);
ctg
RLock
VgInfo
(
pCtg
,
dbCache
,
&
inCache
);
if
(
!
inCache
)
{
if
(
!
inCache
)
{
ctgDebug
(
"vgInfo of db %s not in cache"
,
dbFName
);
ctgDebug
(
"vgInfo of db %s not in cache"
,
dbFName
);
goto
_return
;
goto
_return
;
...
@@ -202,54 +228,160 @@ _return:
...
@@ -202,54 +228,160 @@ _return:
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
ctgTbMetaExistInCache
(
SCatalog
*
pCtg
,
char
*
dbFName
,
char
*
tbName
,
int32_t
*
exist
)
{
int32_t
ctgAcquireTbMetaFromCache
(
SCatalog
*
pCtg
,
char
*
dbFName
,
char
*
tbName
,
SCtgDBCache
**
pDb
,
SCtgTbCache
**
pTb
)
{
if
(
NULL
==
pCtg
->
dbCache
)
{
SCtgDBCache
*
dbCache
=
NULL
;
*
exist
=
0
;
SCtgTbCache
*
pCache
=
NULL
;
ctgWarn
(
"empty db cache, dbFName:%s, tbName:%s"
,
dbFName
,
tbName
);
ctgAcquireDBCache
(
pCtg
,
dbFName
,
&
dbCache
);
if
(
NULL
==
dbCache
)
{
ctgDebug
(
"db %s not in cache"
,
dbFName
);
goto
_return
;
}
int32_t
sz
=
0
;
pCache
=
taosHashAcquire
(
dbCache
->
tbCache
,
tbName
,
strlen
(
tbName
));
if
(
NULL
==
pCache
)
{
ctgDebug
(
"tb %s not in cache, dbFName:%s"
,
tbName
,
dbFName
);
goto
_return
;
}
CTG_LOCK
(
CTG_READ
,
&
pCache
->
metaLock
);
if
(
NULL
==
pCache
->
pMeta
)
{
ctgDebug
(
"tb %s meta not in cache, dbFName:%s"
,
tbName
,
dbFName
);
goto
_return
;
}
*
pDb
=
dbCache
;
*
pTb
=
pCache
;
ctgDebug
(
"tb %s meta got in cache, dbFName:%s"
,
tbName
,
dbFName
);
CTG_CACHE_STAT_INC
(
tbMetaHitNum
,
1
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
_return:
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
pCache
);
CTG_CACHE_STAT_INC
(
tbMetaMissNum
,
1
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
ctgAcquireStbMetaFromCache
(
SCatalog
*
pCtg
,
char
*
dbFName
,
uint64_t
suid
,
SCtgDBCache
**
pDb
,
SCtgTbCache
**
pTb
)
{
SCtgDBCache
*
dbCache
=
NULL
;
SCtgTbCache
*
pCache
=
NULL
;
ctgAcquireDBCache
(
pCtg
,
dbFName
,
&
dbCache
);
if
(
NULL
==
dbCache
)
{
ctgDebug
(
"db %s not in cache"
,
dbFName
);
goto
_return
;
}
int32_t
sz
=
0
;
char
*
stName
=
taosHashAcquire
(
dbCache
->
stbCache
,
&
suid
,
sizeof
(
suid
));
if
(
NULL
==
stName
)
{
ctgDebug
(
"stb %"
PRIx64
" not in cache, dbFName:%s"
,
suid
,
dbFName
);
goto
_return
;
}
pCache
=
taosHashAcquire
(
dbCache
->
tbCache
,
stName
,
strlen
(
stName
));
if
(
NULL
==
pCache
)
{
ctgDebug
(
"stb %"
PRIx64
" name %s not in cache, dbFName:%s"
,
suid
,
stName
,
dbFName
);
taosHashRelease
(
dbCache
->
stbCache
,
stName
);
goto
_return
;
}
CTG_LOCK
(
CTG_READ
,
&
pCache
->
metaLock
);
if
(
NULL
==
pCache
->
pMeta
)
{
ctgDebug
(
"stb %"
PRIx64
" meta not in cache, dbFName:%s"
,
suid
,
dbFName
);
goto
_return
;
}
}
*
pDb
=
dbCache
;
*
pTb
=
pCache
;
ctgDebug
(
"stb %"
PRIx64
" meta got in cache, dbFName:%s"
,
suid
,
dbFName
);
CTG_CACHE_STAT_INC
(
tbMetaHitNum
,
1
);
return
TSDB_CODE_SUCCESS
;
_return:
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
pCache
);
CTG_CACHE_STAT_INC
(
tbMetaMissNum
,
1
);
*
pDb
=
NULL
;
*
pTb
=
NULL
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
ctgAcquireTbIndexFromCache
(
SCatalog
*
pCtg
,
char
*
dbFName
,
char
*
tbName
,
SCtgDBCache
**
pDb
,
SCtgTbCache
**
pTb
)
{
SCtgDBCache
*
dbCache
=
NULL
;
SCtgDBCache
*
dbCache
=
NULL
;
ctgAcquireDBCache
(
pCtg
,
dbFName
,
&
dbCache
);
ctgAcquireDBCache
(
pCtg
,
dbFName
,
&
dbCache
);
if
(
NULL
==
dbCache
)
{
if
(
NULL
==
dbCache
)
{
*
exist
=
0
;
ctgDebug
(
"db %s not in cache"
,
dbFName
)
;
return
TSDB_CODE_SUCCESS
;
goto
_return
;
}
}
size_t
sz
=
0
;
int32_t
sz
=
0
;
CTG_LOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
metaLock
);
SCtgTbCache
*
pCache
=
taosHashAcquire
(
dbCache
->
tbCache
,
tbName
,
strlen
(
tbName
));
STableMeta
*
tbMeta
=
taosHashGet
(
dbCache
->
tbCache
.
metaCache
,
tbName
,
strlen
(
tbName
));
if
(
NULL
==
pCache
)
{
CTG_UNLOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
metaLock
);
ctgDebug
(
"tb %s not in cache, dbFName:%s"
,
tbName
,
dbFName
);
goto
_return
;
}
if
(
NULL
==
tbMeta
)
{
CTG_LOCK
(
CTG_READ
,
&
pCache
->
indexLock
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
if
(
NULL
==
pCache
->
pIndex
)
{
ctgDebug
(
"tb %s index not in cache, dbFName:%s"
,
tbName
,
dbFName
);
goto
_return
;
}
*
pDb
=
dbCache
;
*
pTb
=
pCache
;
ctgDebug
(
"tb %s index got in cache, dbFName:%s"
,
tbName
,
dbFName
);
CTG_CACHE_STAT_INC
(
tbIndexHitNum
,
1
);
*
exist
=
0
;
ctgDebug
(
"tbmeta not in cache, dbFName:%s, tbName:%s"
,
dbFName
,
tbName
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
*
exist
=
1
;
_return:
ctgRelease
DBCache
(
pCtg
,
db
Cache
);
ctgRelease
TbIndexToCache
(
pCtg
,
dbCache
,
p
Cache
);
ctgDebug
(
"tbmeta is in cache, dbFName:%s, tbName:%s"
,
dbFName
,
tbName
);
CTG_CACHE_STAT_INC
(
tbIndexMissNum
,
1
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
ctgReadTbMetaFromCache
(
SCatalog
*
pCtg
,
SCtgTbMetaCtx
*
ctx
,
STableMeta
**
pTableMeta
)
{
int32_t
ctgTbMetaExistInCache
(
SCatalog
*
pCtg
,
char
*
dbFName
,
char
*
tbName
,
int32_t
*
exist
)
{
int32_t
code
=
0
;
SCtgDBCache
*
dbCache
=
NULL
;
SCtgDBCache
*
dbCache
=
NULL
;
SCtgTbCache
*
tbCache
=
NULL
;
ctgAcquireTbMetaFromCache
(
pCtg
,
dbFName
,
tbName
,
&
dbCache
,
&
tbCache
);
if
(
NULL
==
tbCache
)
{
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
tbCache
);
*
pTableMeta
=
NULL
;
*
exist
=
0
;
if
(
NULL
==
pCtg
->
dbCache
)
{
ctgDebug
(
"empty tbmeta cache, tbName:%s"
,
ctx
->
pName
->
tname
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
*
exist
=
1
;
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
tbCache
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
ctgReadTbMetaFromCache
(
SCatalog
*
pCtg
,
SCtgTbMetaCtx
*
ctx
,
STableMeta
**
pTableMeta
)
{
int32_t
code
=
0
;
SCtgDBCache
*
dbCache
=
NULL
;
SCtgTbCache
*
tbCache
=
NULL
;
*
pTableMeta
=
NULL
;
char
dbFName
[
TSDB_DB_FNAME_LEN
]
=
{
0
};
char
dbFName
[
TSDB_DB_FNAME_LEN
]
=
{
0
};
if
(
CTG_FLAG_IS_SYS_DB
(
ctx
->
flag
))
{
if
(
CTG_FLAG_IS_SYS_DB
(
ctx
->
flag
))
{
strcpy
(
dbFName
,
ctx
->
pName
->
dbname
);
strcpy
(
dbFName
,
ctx
->
pName
->
dbname
);
...
@@ -257,202 +389,194 @@ int32_t ctgReadTbMetaFromCache(SCatalog* pCtg, SCtgTbMetaCtx* ctx, STableMeta**
...
@@ -257,202 +389,194 @@ int32_t ctgReadTbMetaFromCache(SCatalog* pCtg, SCtgTbMetaCtx* ctx, STableMeta**
tNameGetFullDbName
(
ctx
->
pName
,
dbFName
);
tNameGetFullDbName
(
ctx
->
pName
,
dbFName
);
}
}
ctgAcquireDBCache
(
pCtg
,
dbFName
,
&
dbCache
);
ctgAcquireTbMetaFromCache
(
pCtg
,
dbFName
,
ctx
->
pName
->
tname
,
&
dbCache
,
&
tbCache
);
if
(
NULL
==
dbCache
)
{
if
(
NULL
==
tbCache
)
{
ctgDebug
(
"db %d.%s not in cache"
,
ctx
->
pName
->
acctId
,
ctx
->
pName
->
dbname
);
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
tbCache
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
sz
=
0
;
CTG_LOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
metaLock
);
taosHashGetDup_m
(
dbCache
->
tbCache
.
metaCache
,
ctx
->
pName
->
tname
,
strlen
(
ctx
->
pName
->
tname
),
(
void
**
)
pTableMeta
,
&
sz
);
CTG_UNLOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
metaLock
);
if
(
NULL
==
*
pTableMeta
)
{
ctgReleaseDBCache
(
pCtg
,
dbCache
);
ctgDebug
(
"tbl not in cache, dbFName:%s, tbName:%s"
,
dbFName
,
ctx
->
pName
->
tname
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
STableMeta
*
tbMeta
=
*
pTable
Meta
;
STableMeta
*
tbMeta
=
tbCache
->
p
Meta
;
ctx
->
tbInfo
.
inCache
=
true
;
ctx
->
tbInfo
.
inCache
=
true
;
ctx
->
tbInfo
.
dbId
=
dbCache
->
dbId
;
ctx
->
tbInfo
.
dbId
=
dbCache
->
dbId
;
ctx
->
tbInfo
.
suid
=
tbMeta
->
suid
;
ctx
->
tbInfo
.
suid
=
tbMeta
->
suid
;
ctx
->
tbInfo
.
tbType
=
tbMeta
->
tableType
;
ctx
->
tbInfo
.
tbType
=
tbMeta
->
tableType
;
if
(
tbMeta
->
tableType
!=
TSDB_CHILD_TABLE
)
{
if
(
tbMeta
->
tableType
!=
TSDB_CHILD_TABLE
)
{
ctgReleaseDBCache
(
pCtg
,
dbCache
);
int32_t
metaSize
=
CTG_META_SIZE
(
tbMeta
);
ctgDebug
(
"Got meta from cache, type:%d, dbFName:%s, tbName:%s"
,
tbMeta
->
tableType
,
dbFName
,
ctx
->
pName
->
tname
);
*
pTableMeta
=
taosMemoryCalloc
(
1
,
metaSize
);
if
(
NULL
==
*
pTableMeta
)
{
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
tbCache
);
CTG_ERR_JRET
(
TSDB_CODE_OUT_OF_MEMORY
);
}
CTG_CACHE_STAT_INC
(
tblHitNum
,
1
);
memcpy
(
*
pTableMeta
,
tbMeta
,
metaSize
);
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
tbCache
);
ctgDebug
(
"Got tb %s meta from cache, type:%d, dbFName:%s"
,
ctx
->
pName
->
tname
,
tbMeta
->
tableType
,
dbFName
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
CTG_LOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
stbLock
);
// PROCESS FOR CHILD TABLE
STableMeta
**
stbMeta
=
taosHashGet
(
dbCache
->
tbCache
.
stbCache
,
&
tbMeta
->
suid
,
sizeof
(
tbMeta
->
suid
));
int32_t
metaSize
=
sizeof
(
SCTableMeta
);
if
(
NULL
==
stbMeta
||
NULL
==
*
stbMeta
)
{
*
pTableMeta
=
taosMemoryCalloc
(
1
,
metaSize
);
CTG_UNLOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
stbLock
);
if
(
NULL
==
*
pTableMeta
)
{
ctgError
(
"stb not in stbCache, suid:%"
PRIx64
,
tbMeta
->
suid
);
CTG_ERR_JRET
(
TSDB_CODE_OUT_OF_MEMORY
);
goto
_return
;
}
memcpy
(
*
pTableMeta
,
tbMeta
,
metaSize
);
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
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 %"
PRIx64
" meta not in cache"
,
ctx
->
tbInfo
.
suid
);
return
TSDB_CODE_SUCCESS
;
}
}
if
((
*
stbMeta
)
->
suid
!=
tbMeta
->
suid
)
{
STableMeta
*
stbMeta
=
tbCache
->
pMeta
;
CTG_UNLOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
stbLock
);
if
(
stbMeta
->
suid
!=
ctx
->
tbInfo
.
suid
)
{
ctgError
(
"stable suid in stbCache mis-match, expected suid:%"
PRIx64
",actual suid:%"
PRIx64
,
tbMeta
->
suid
,
(
*
stbMeta
)
->
suid
);
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
tbCache
);
ctgError
(
"stb suid %"
PRIx64
" in stbCache mis-match, expected suid:%"
PRIx64
,
stbMeta
->
suid
,
ctx
->
tbInfo
.
suid
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
}
}
int32_t
metaSize
=
CTG_META_SIZE
(
*
stbMeta
);
metaSize
=
CTG_META_SIZE
(
stbMeta
);
*
pTableMeta
=
taosMemoryRealloc
(
*
pTableMeta
,
metaSize
);
*
pTableMeta
=
taosMemoryRealloc
(
*
pTableMeta
,
metaSize
);
if
(
NULL
==
*
pTableMeta
)
{
if
(
NULL
==
*
pTableMeta
)
{
CTG_UNLOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
stbLock
);
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
tbCache
);
ctgError
(
"realloc size[%d] failed"
,
metaSize
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_MEM_ERROR
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
}
memcpy
(
&
(
*
pTableMeta
)
->
sversion
,
&
(
*
stbMeta
)
->
sversion
,
metaSize
-
sizeof
(
SCTableMeta
));
memcpy
(
&
(
*
pTableMeta
)
->
sversion
,
&
stbMeta
->
sversion
,
metaSize
-
sizeof
(
SCTableMeta
));
CTG_UNLOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
stbLock
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
CTG_CACHE_STAT_INC
(
tblHitNum
,
1
);
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
tbCache
);
ctgDebug
(
"Got tb
meta from cache, dbFName:%s, tbName:%s"
,
dbFName
,
ctx
->
pName
->
tn
ame
);
ctgDebug
(
"Got tb
%s meta from cache, dbFName:%s"
,
ctx
->
pName
->
tname
,
dbFN
ame
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
_return:
_return:
ctgRelease
DBCache
(
pCtg
,
d
bCache
);
ctgRelease
TbMetaToCache
(
pCtg
,
dbCache
,
t
bCache
);
taosMemoryFreeClear
(
*
pTableMeta
);
taosMemoryFreeClear
(
*
pTableMeta
);
CTG_CACHE_STAT_INC
(
tblMissNum
,
1
);
CTG_RET
(
code
);
CTG_RET
(
code
);
}
}
int32_t
ctgReadTbVerFromCache
(
SCatalog
*
pCtg
,
const
SName
*
pTableName
,
int32_t
*
sver
,
int32_t
*
tver
,
int32_t
*
tbType
,
uint64_t
*
suid
,
int32_t
ctgReadTbVerFromCache
(
SCatalog
*
pCtg
,
SName
*
pTableName
,
int32_t
*
sver
,
int32_t
*
tver
,
int32_t
*
tbType
,
uint64_t
*
suid
,
char
*
stbName
)
{
char
*
stbName
)
{
*
sver
=
-
1
;
*
sver
=
-
1
;
*
tver
=
-
1
;
*
tver
=
-
1
;
if
(
NULL
==
pCtg
->
dbCache
)
{
ctgDebug
(
"empty tbmeta cache, tbName:%s"
,
pTableName
->
tname
);
return
TSDB_CODE_SUCCESS
;
}
SCtgDBCache
*
dbCache
=
NULL
;
SCtgDBCache
*
dbCache
=
NULL
;
SCtgTbCache
*
tbCache
=
NULL
;
char
dbFName
[
TSDB_DB_FNAME_LEN
]
=
{
0
};
char
dbFName
[
TSDB_DB_FNAME_LEN
]
=
{
0
};
tNameGetFullDbName
(
pTableName
,
dbFName
);
tNameGetFullDbName
(
pTableName
,
dbFName
);
ctgAcquire
DBCache
(
pCtg
,
dbFName
,
&
d
bCache
);
ctgAcquire
TbMetaFromCache
(
pCtg
,
dbFName
,
pTableName
->
tname
,
&
dbCache
,
&
t
bCache
);
if
(
NULL
==
d
bCache
)
{
if
(
NULL
==
t
bCache
)
{
ctg
Debug
(
"db %s not in cache"
,
pTableName
->
tnam
e
);
ctg
ReleaseTbMetaToCache
(
pCtg
,
dbCache
,
tbCach
e
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
CTG_LOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
metaLock
);
STableMeta
*
tbMeta
=
tbCache
->
pMeta
;
STableMeta
*
tbMeta
=
taosHashGet
(
dbCache
->
tbCache
.
metaCache
,
pTableName
->
tname
,
strlen
(
pTableName
->
tname
));
if
(
tbMeta
)
{
*
tbType
=
tbMeta
->
tableType
;
*
tbType
=
tbMeta
->
tableType
;
*
suid
=
tbMeta
->
suid
;
*
suid
=
tbMeta
->
suid
;
if
(
*
tbType
!=
TSDB_CHILD_TABLE
)
{
if
(
*
tbType
!=
TSDB_CHILD_TABLE
)
{
*
sver
=
tbMeta
->
sversion
;
*
sver
=
tbMeta
->
sversion
;
*
tver
=
tbMeta
->
tversion
;
*
tver
=
tbMeta
->
tversion
;
}
}
CTG_UNLOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
metaLock
);
if
(
NULL
==
tbMeta
)
{
ctgDebug
(
"Got tb %s ver from cache, dbFName:%s, tbType:%d, sver:%d, tver:%d, suid:%"
PRIx64
,
ctgReleaseDBCache
(
pCtg
,
dbCache
);
pTableName
->
tname
,
dbFName
,
*
tbType
,
*
sver
,
*
tver
,
*
suid
);
return
TSDB_CODE_SUCCESS
;
}
if
(
*
tbType
!=
TSDB_CHILD_TABLE
)
{
ctgReleaseDBCache
(
pCtg
,
dbCache
);
ctgDebug
(
"Got sver %d tver %d from cache, type:%d, dbFName:%s, tbName:%s"
,
*
sver
,
*
tver
,
*
tbType
,
dbFName
,
pTableName
->
tname
);
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
tbCache
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
ctgDebug
(
"Got subtable meta from cache, dbFName:%s, tbName:%s, suid:%"
PRIx64
,
dbFName
,
pTableName
->
tname
,
*
suid
);
// PROCESS FOR CHILD TABLE
CTG_LOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
stbLock
);
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
tbCache
);
ctgDebug
(
"Got ctb %s ver from cache, will continue to get its stb ver, dbFName:%s"
,
pTableName
->
tname
,
dbFName
);
STableMeta
**
stbMeta
=
taosHashGet
(
dbCache
->
tbCache
.
stbCache
,
suid
,
sizeof
(
*
suid
));
ctgAcquireStbMetaFromCache
(
pCtg
,
dbFName
,
*
suid
,
&
dbCache
,
&
tbCache
);
if
(
NULL
==
stbMeta
||
NULL
==
*
stbMeta
)
{
if
(
NULL
==
tbCache
)
{
CTG_UNLOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
stbLock
);
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
tbCache
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
ctgDebug
(
"stb %"
PRIx64
" meta not in cache"
,
*
suid
);
ctgDebug
(
"stb not in stbCache, suid:%"
PRIx64
,
*
suid
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
if
((
*
stbMeta
)
->
suid
!=
*
suid
)
{
STableMeta
*
stbMeta
=
tbCache
->
pMeta
;
CTG_UNLOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
stbLock
);
if
(
stbMeta
->
suid
!=
*
suid
)
{
ctgReleaseDBCache
(
pCtg
,
dbCache
);
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
tbCache
);
ctgError
(
"stable suid in stbCache mis-match, expected suid:%"
PRIx64
",actual suid:%"
PRIx64
,
*
suid
,
ctgError
(
"stb suid %"
PRIx64
" in stbCache mis-match, expected suid:%"
PRIx64
,
stbMeta
->
suid
,
*
suid
);
(
*
stbMeta
)
->
suid
);
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
}
}
size_t
nameLen
=
0
;
size_t
nameLen
=
0
;
char
*
name
=
taosHashGetKey
(
*
stbMeta
,
&
nameLen
);
char
*
name
=
taosHashGetKey
(
tbCache
,
&
nameLen
);
strncpy
(
stbName
,
name
,
nameLen
);
strncpy
(
stbName
,
name
,
nameLen
);
stbName
[
nameLen
]
=
0
;
stbName
[
nameLen
]
=
0
;
*
sver
=
(
*
stbMeta
)
->
sversion
;
*
sver
=
stbMeta
->
sversion
;
*
tver
=
(
*
stbMeta
)
->
tversion
;
*
tver
=
stbMeta
->
tversion
;
CTG_UNLOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
stbLock
);
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
tbCache
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
ctgDebug
(
"Got tb %s sver %d tver %d from cache, type:%d, dbFName:%s"
,
pTableName
->
tname
,
*
sver
,
*
tver
,
*
tbType
,
dbFName
);
ctgDebug
(
"Got sver %d tver %d from cache, type:%d, dbFName:%s, tbName:%s"
,
*
sver
,
*
tver
,
*
tbType
,
dbFName
,
pTableName
->
tname
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
ctgReadTbTypeFromCache
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
const
char
*
tableName
,
int32_t
*
tbType
)
{
int32_t
ctgReadTbTypeFromCache
(
SCatalog
*
pCtg
,
char
*
dbFName
,
char
*
tableName
,
int32_t
*
tbType
)
{
if
(
NULL
==
pCtg
->
dbCache
)
{
ctgWarn
(
"empty db cache, dbFName:%s, tbName:%s"
,
dbFName
,
tableName
);
return
TSDB_CODE_SUCCESS
;
}
SCtgDBCache
*
dbCache
=
NULL
;
SCtgDBCache
*
dbCache
=
NULL
;
ctgAcquireDBCache
(
pCtg
,
dbFName
,
&
dbCache
);
SCtgTbCache
*
tbCache
=
NULL
;
if
(
NULL
==
dbCache
)
{
CTG_ERR_RET
(
ctgAcquireTbMetaFromCache
(
pCtg
,
dbFName
,
tableName
,
&
dbCache
,
&
tbCache
));
if
(
NULL
==
tbCache
)
{
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
tbCache
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
CTG_LOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
metaLock
)
;
*
tbType
=
tbCache
->
pMeta
->
tableType
;
STableMeta
*
pTableMeta
=
(
STableMeta
*
)
taosHashAcquire
(
dbCache
->
tbCache
.
metaCache
,
tableName
,
strlen
(
tableName
)
);
ctgReleaseTbMetaToCache
(
pCtg
,
dbCache
,
tbCache
);
if
(
NULL
==
pTableMeta
)
{
ctgDebug
(
"Got tb %s tbType %d from cache, dbFName:%s"
,
tableName
,
*
tbType
,
dbFName
);
CTG_UNLOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
metaLock
);
ctgWarn
(
"tbl not in cache, dbFName:%s, tbName:%s"
,
dbFName
,
tableName
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
ctgReadTbIndexFromCache
(
SCatalog
*
pCtg
,
SName
*
pTableName
,
SArray
**
pRes
)
{
int32_t
code
=
0
;
SCtgDBCache
*
dbCache
=
NULL
;
SCtgTbCache
*
tbCache
=
NULL
;
char
dbFName
[
TSDB_DB_FNAME_LEN
]
=
{
0
};
tNameGetFullDbName
(
pTableName
,
dbFName
);
*
tbType
=
atomic_load_8
(
&
pTableMeta
->
tableType
)
;
*
pRes
=
NULL
;
taosHashRelease
(
dbCache
->
tbCache
.
metaCache
,
pTableMeta
);
ctgAcquireTbIndexFromCache
(
pCtg
,
dbFName
,
pTableName
->
tname
,
&
dbCache
,
&
tbCache
);
if
(
NULL
==
tbCache
)
{
ctgReleaseTbIndexToCache
(
pCtg
,
dbCache
,
tbCache
);
return
TSDB_CODE_SUCCESS
;
}
CTG_
UNLOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
metaLock
);
CTG_
ERR_JRET
(
ctgCloneTableIndex
(
tbCache
->
pIndex
->
pIndex
,
pRes
)
);
ctgReleaseDBCache
(
pCtg
,
dbCache
);
_return:
ctg
Debug
(
"Got tbtype from cache, dbFName:%s, tbName:%s, type:%d"
,
dbFName
,
tableName
,
*
tbType
);
ctg
ReleaseTbIndexToCache
(
pCtg
,
dbCache
,
tbCache
);
return
TSDB_CODE_SUCCESS
;
CTG_RET
(
code
)
;
}
}
int32_t
ctgChkAuthFromCache
(
SCatalog
*
pCtg
,
c
onst
char
*
user
,
const
char
*
dbFName
,
AUTH_TYPE
type
,
bool
*
inCache
,
bool
*
pass
)
{
int32_t
ctgChkAuthFromCache
(
SCatalog
*
pCtg
,
c
har
*
user
,
char
*
dbFName
,
AUTH_TYPE
type
,
bool
*
inCache
,
bool
*
pass
)
{
if
(
NULL
==
pCtg
->
userCache
)
{
if
(
NULL
==
pCtg
->
userCache
)
{
ctgDebug
(
"empty user auth cache, user:%s"
,
user
);
ctgDebug
(
"empty user auth cache, user:%s"
,
user
);
goto
_return
;
goto
_return
;
...
@@ -718,9 +842,9 @@ int32_t ctgUpdateTbMetaEnqueue(SCatalog* pCtg, STableMetaOutput *output, bool sy
...
@@ -718,9 +842,9 @@ int32_t ctgUpdateTbMetaEnqueue(SCatalog* pCtg, STableMetaOutput *output, bool sy
op
->
opId
=
CTG_OP_UPDATE_TB_META
;
op
->
opId
=
CTG_OP_UPDATE_TB_META
;
op
->
syncOp
=
syncOp
;
op
->
syncOp
=
syncOp
;
SCtgUpdateTb
lMsg
*
msg
=
taosMemoryMalloc
(
sizeof
(
SCtgUpdateTbl
Msg
));
SCtgUpdateTb
MetaMsg
*
msg
=
taosMemoryMalloc
(
sizeof
(
SCtgUpdateTbMeta
Msg
));
if
(
NULL
==
msg
)
{
if
(
NULL
==
msg
)
{
ctgError
(
"malloc %d failed"
,
(
int32_t
)
sizeof
(
SCtgUpdateTb
l
Msg
));
ctgError
(
"malloc %d failed"
,
(
int32_t
)
sizeof
(
SCtgUpdateTb
Meta
Msg
));
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
}
...
@@ -730,7 +854,7 @@ int32_t ctgUpdateTbMetaEnqueue(SCatalog* pCtg, STableMetaOutput *output, bool sy
...
@@ -730,7 +854,7 @@ int32_t ctgUpdateTbMetaEnqueue(SCatalog* pCtg, STableMetaOutput *output, bool sy
}
}
msg
->
pCtg
=
pCtg
;
msg
->
pCtg
=
pCtg
;
msg
->
output
=
output
;
msg
->
pMeta
=
output
;
op
->
data
=
msg
;
op
->
data
=
msg
;
...
@@ -805,6 +929,67 @@ _return:
...
@@ -805,6 +929,67 @@ _return:
CTG_RET
(
code
);
CTG_RET
(
code
);
}
}
int32_t
ctgUpdateTbIndexEnqueue
(
SCatalog
*
pCtg
,
STableIndex
**
pIndex
,
bool
syncOp
)
{
int32_t
code
=
0
;
SCtgCacheOperation
*
op
=
taosMemoryCalloc
(
1
,
sizeof
(
SCtgCacheOperation
));
op
->
opId
=
CTG_OP_UPDATE_TB_INDEX
;
op
->
syncOp
=
syncOp
;
SCtgUpdateTbIndexMsg
*
msg
=
taosMemoryMalloc
(
sizeof
(
SCtgUpdateTbIndexMsg
));
if
(
NULL
==
msg
)
{
ctgError
(
"malloc %d failed"
,
(
int32_t
)
sizeof
(
SCtgUpdateTbIndexMsg
));
CTG_ERR_JRET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
msg
->
pCtg
=
pCtg
;
msg
->
pIndex
=
*
pIndex
;
op
->
data
=
msg
;
CTG_ERR_JRET
(
ctgEnqueue
(
pCtg
,
op
));
*
pIndex
=
NULL
;
return
TSDB_CODE_SUCCESS
;
_return:
taosArrayDestroyEx
((
*
pIndex
)
->
pIndex
,
tFreeSTableIndexInfo
);
taosMemoryFreeClear
(
*
pIndex
);
taosMemoryFreeClear
(
msg
);
CTG_RET
(
code
);
}
int32_t
ctgDropTbIndexEnqueue
(
SCatalog
*
pCtg
,
SName
*
pName
,
bool
syncOp
)
{
int32_t
code
=
0
;
SCtgCacheOperation
*
op
=
taosMemoryCalloc
(
1
,
sizeof
(
SCtgCacheOperation
));
op
->
opId
=
CTG_OP_DROP_TB_INDEX
;
op
->
syncOp
=
syncOp
;
SCtgDropTbIndexMsg
*
msg
=
taosMemoryMalloc
(
sizeof
(
SCtgDropTbIndexMsg
));
if
(
NULL
==
msg
)
{
ctgError
(
"malloc %d failed"
,
(
int32_t
)
sizeof
(
SCtgDropTbIndexMsg
));
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
msg
->
pCtg
=
pCtg
;
tNameGetFullDbName
(
pName
,
msg
->
dbFName
);
strcpy
(
msg
->
tbName
,
pName
->
tname
);
op
->
data
=
msg
;
CTG_ERR_JRET
(
ctgEnqueue
(
pCtg
,
op
));
return
TSDB_CODE_SUCCESS
;
_return:
taosMemoryFreeClear
(
msg
);
CTG_RET
(
code
);
}
int32_t
ctgMetaRentInit
(
SCtgRentMgmt
*
mgmt
,
uint32_t
rentSec
,
int8_t
type
)
{
int32_t
ctgMetaRentInit
(
SCtgRentMgmt
*
mgmt
,
uint32_t
rentSec
,
int8_t
type
)
{
mgmt
->
slotRIdx
=
0
;
mgmt
->
slotRIdx
=
0
;
mgmt
->
slotNum
=
rentSec
/
CTG_RENT_SLOT_SECOND
;
mgmt
->
slotNum
=
rentSec
/
CTG_RENT_SLOT_SECOND
;
...
@@ -875,7 +1060,7 @@ int32_t ctgMetaRentUpdate(SCtgRentMgmt *mgmt, void *meta, int64_t id, int32_t si
...
@@ -875,7 +1060,7 @@ int32_t ctgMetaRentUpdate(SCtgRentMgmt *mgmt, void *meta, int64_t id, int32_t si
void
*
orig
=
taosArraySearch
(
slot
->
meta
,
&
id
,
searchCompare
,
TD_EQ
);
void
*
orig
=
taosArraySearch
(
slot
->
meta
,
&
id
,
searchCompare
,
TD_EQ
);
if
(
NULL
==
orig
)
{
if
(
NULL
==
orig
)
{
q
Error
(
"meta not found in slot, id:%"
PRIx64
", slot idx:%d, type:%d, size:%d"
,
id
,
widx
,
mgmt
->
type
,
(
int32_t
)
taosArrayGetSize
(
slot
->
meta
));
q
Debug
(
"meta not found in slot, id:%"
PRIx64
", slot idx:%d, type:%d, size:%d"
,
id
,
widx
,
mgmt
->
type
,
(
int32_t
)
taosArrayGetSize
(
slot
->
meta
));
CTG_ERR_JRET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
}
}
...
@@ -888,7 +1073,7 @@ _return:
...
@@ -888,7 +1073,7 @@ _return:
CTG_UNLOCK
(
CTG_WRITE
,
&
slot
->
lock
);
CTG_UNLOCK
(
CTG_WRITE
,
&
slot
->
lock
);
if
(
code
)
{
if
(
code
)
{
q
Warn
(
"meta in rent update failed, will try to add it, code:%x, id:%"
PRIx64
", slot idx:%d, type:%d"
,
code
,
id
,
widx
,
mgmt
->
type
);
q
Debug
(
"meta in rent update failed, will try to add it, code:%x, id:%"
PRIx64
", slot idx:%d, type:%d"
,
code
,
id
,
widx
,
mgmt
->
type
);
CTG_RET
(
ctgMetaRentAdd
(
mgmt
,
meta
,
id
,
size
));
CTG_RET
(
ctgMetaRentAdd
(
mgmt
,
meta
,
id
,
size
));
}
}
...
@@ -1006,14 +1191,14 @@ int32_t ctgAddNewDBCache(SCatalog *pCtg, const char *dbFName, uint64_t dbId) {
...
@@ -1006,14 +1191,14 @@ int32_t ctgAddNewDBCache(SCatalog *pCtg, const char *dbFName, uint64_t dbId) {
SCtgDBCache
newDBCache
=
{
0
};
SCtgDBCache
newDBCache
=
{
0
};
newDBCache
.
dbId
=
dbId
;
newDBCache
.
dbId
=
dbId
;
newDBCache
.
tbCache
.
metaCache
=
taosHashInit
(
gCtgMgmt
.
cfg
.
maxTblCacheNum
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
newDBCache
.
tbCache
=
taosHashInit
(
gCtgMgmt
.
cfg
.
maxTblCacheNum
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
if
(
NULL
==
newDBCache
.
tbCache
.
metaCache
)
{
if
(
NULL
==
newDBCache
.
tbCache
)
{
ctgError
(
"taosHashInit %d metaCache failed"
,
gCtgMgmt
.
cfg
.
maxTblCacheNum
);
ctgError
(
"taosHashInit %d metaCache failed"
,
gCtgMgmt
.
cfg
.
maxTblCacheNum
);
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
}
newDBCache
.
tbCache
.
stbCache
=
taosHashInit
(
gCtgMgmt
.
cfg
.
maxTblCacheNum
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_UBIGINT
),
true
,
HASH_ENTRY_LOCK
);
newDBCache
.
stbCache
=
taosHashInit
(
gCtgMgmt
.
cfg
.
maxTblCacheNum
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_UBIGINT
),
true
,
HASH_ENTRY_LOCK
);
if
(
NULL
==
newDBCache
.
tbCache
.
stbCache
)
{
if
(
NULL
==
newDBCache
.
stbCache
)
{
ctgError
(
"taosHashInit %d stbCache failed"
,
gCtgMgmt
.
cfg
.
maxTblCacheNum
);
ctgError
(
"taosHashInit %d stbCache failed"
,
gCtgMgmt
.
cfg
.
maxTblCacheNum
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_MEM_ERROR
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
}
...
@@ -1050,10 +1235,12 @@ _return:
...
@@ -1050,10 +1235,12 @@ _return:
}
}
void
ctgRemoveStbRent
(
SCatalog
*
pCtg
,
SCtgTbMetaCache
*
cache
)
{
void
ctgRemoveStbRent
(
SCatalog
*
pCtg
,
SCtgDBCache
*
dbCache
)
{
CTG_LOCK
(
CTG_WRITE
,
&
cache
->
stbLock
);
if
(
NULL
==
dbCache
->
stbCache
)
{
if
(
cache
->
stbCache
)
{
return
;
void
*
pIter
=
taosHashIterate
(
cache
->
stbCache
,
NULL
);
}
void
*
pIter
=
taosHashIterate
(
dbCache
->
stbCache
,
NULL
);
while
(
pIter
)
{
while
(
pIter
)
{
uint64_t
*
suid
=
NULL
;
uint64_t
*
suid
=
NULL
;
suid
=
taosHashGetKey
(
pIter
,
NULL
);
suid
=
taosHashGetKey
(
pIter
,
NULL
);
...
@@ -1062,10 +1249,8 @@ void ctgRemoveStbRent(SCatalog* pCtg, SCtgTbMetaCache *cache) {
...
@@ -1062,10 +1249,8 @@ void ctgRemoveStbRent(SCatalog* pCtg, SCtgTbMetaCache *cache) {
ctgDebug
(
"stb removed from rent, suid:%"
PRIx64
,
*
suid
);
ctgDebug
(
"stb removed from rent, suid:%"
PRIx64
,
*
suid
);
}
}
pIter
=
taosHashIterate
(
cache
->
stbCache
,
pIter
);
pIter
=
taosHashIterate
(
dbCache
->
stbCache
,
pIter
);
}
}
}
CTG_UNLOCK
(
CTG_WRITE
,
&
cache
->
stbLock
);
}
}
...
@@ -1074,15 +1259,16 @@ int32_t ctgRemoveDBFromCache(SCatalog* pCtg, SCtgDBCache *dbCache, const char* d
...
@@ -1074,15 +1259,16 @@ int32_t ctgRemoveDBFromCache(SCatalog* pCtg, SCtgDBCache *dbCache, const char* d
ctgInfo
(
"start to remove db from cache, dbFName:%s, dbId:%"
PRIx64
,
dbFName
,
dbCache
->
dbId
);
ctgInfo
(
"start to remove db from cache, dbFName:%s, dbId:%"
PRIx64
,
dbFName
,
dbCache
->
dbId
);
atomic_store_8
(
&
dbCache
->
deleted
,
1
);
CTG_LOCK
(
CTG_WRITE
,
&
dbCache
->
dbLock
);
ctgRemoveStbRent
(
pCtg
,
&
dbCache
->
tbCache
);
atomic_store_8
(
&
dbCache
->
deleted
,
1
);
ctgRemoveStbRent
(
pCtg
,
dbCache
);
ctgFreeDbCache
(
dbCache
);
ctgFreeDbCache
(
dbCache
);
CTG_
ERR_RET
(
ctgMetaRentRemove
(
&
pCtg
->
dbRent
,
dbCache
->
dbId
,
ctgDbVgVersionSortCompare
,
ctgDbVgVersionSearchCompare
)
);
CTG_
UNLOCK
(
CTG_WRITE
,
&
dbCache
->
dbLock
);
ctgDebug
(
"db removed from rent, dbFName:%s, dbId:%"
PRIx64
,
dbFName
,
dbCache
->
dbId
);
CTG_ERR_RET
(
ctgMetaRentRemove
(
&
pCtg
->
dbRent
,
dbId
,
ctgDbVgVersionSortCompare
,
ctgDbVgVersionSearchCompare
));
ctgDebug
(
"db removed from rent, dbFName:%s, dbId:%"
PRIx64
,
dbFName
,
dbId
);
if
(
taosHashRemove
(
pCtg
->
dbCache
,
dbFName
,
strlen
(
dbFName
)))
{
if
(
taosHashRemove
(
pCtg
->
dbCache
,
dbFName
,
strlen
(
dbFName
)))
{
ctgInfo
(
"taosHashRemove from dbCache failed, may be removed, dbFName:%s"
,
dbFName
);
ctgInfo
(
"taosHashRemove from dbCache failed, may be removed, dbFName:%s"
,
dbFName
);
...
@@ -1090,7 +1276,6 @@ int32_t ctgRemoveDBFromCache(SCatalog* pCtg, SCtgDBCache *dbCache, const char* d
...
@@ -1090,7 +1276,6 @@ int32_t ctgRemoveDBFromCache(SCatalog* pCtg, SCtgDBCache *dbCache, const char* d
}
}
CTG_CACHE_STAT_DEC
(
dbNum
,
1
);
CTG_CACHE_STAT_DEC
(
dbNum
,
1
);
ctgInfo
(
"db removed from cache, dbFName:%s, dbId:%"
PRIx64
,
dbFName
,
dbId
);
ctgInfo
(
"db removed from cache, dbFName:%s, dbId:%"
PRIx64
,
dbFName
,
dbId
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -1138,120 +1323,76 @@ int32_t ctgGetAddDBCache(SCatalog* pCtg, const char *dbFName, uint64_t dbId, SCt
...
@@ -1138,120 +1323,76 @@ int32_t ctgGetAddDBCache(SCatalog* pCtg, const char *dbFName, uint64_t dbId, SCt
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
ctgUpdateRentStbVersion
(
SCatalog
*
pCtg
,
char
*
dbFName
,
char
*
tbName
,
uint64_t
dbId
,
uint64_t
suid
,
SCtgTbCache
*
pCache
)
{
int32_t
ctgWriteDBVgInfoToCache
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
uint64_t
dbId
,
SDBVgInfo
**
pDbInfo
)
{
SSTableVersion
metaRent
=
{.
dbId
=
dbId
,
.
suid
=
suid
};
int32_t
code
=
0
;
if
(
pCache
->
pMeta
)
{
SDBVgInfo
*
dbInfo
=
*
pDbInfo
;
metaRent
.
sversion
=
pCache
->
pMeta
->
sversion
;
metaRent
.
tversion
=
pCache
->
pMeta
->
tversion
;
if
(
NULL
==
dbInfo
->
vgHash
)
{
return
TSDB_CODE_SUCCESS
;
}
}
if
(
dbInfo
->
vgVersion
<
0
||
taosHashGetSize
(
dbInfo
->
vgHash
)
<=
0
)
{
if
(
pCache
->
pIndex
)
{
ctgError
(
"invalid db vgInfo, dbFName:%s, vgHash:%p, vgVersion:%d, vgHashSize:%d"
,
metaRent
.
smaVer
=
pCache
->
pIndex
->
version
;
dbFName
,
dbInfo
->
vgHash
,
dbInfo
->
vgVersion
,
taosHashGetSize
(
dbInfo
->
vgHash
));
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
}
bool
newAdded
=
false
;
strcpy
(
metaRent
.
dbFName
,
dbFName
);
SDbVgVersion
vgVersion
=
{.
dbId
=
dbId
,
.
vgVersion
=
dbInfo
->
vgVersion
,
.
numOfTable
=
dbInfo
->
numOfTable
};
strcpy
(
metaRent
.
stbName
,
tbName
);
SCtgDBCache
*
dbCache
=
NULL
;
CTG_ERR_RET
(
ctgGetAddDBCache
(
pCtg
,
dbFName
,
dbId
,
&
dbCache
));
if
(
NULL
==
dbCache
)
{
ctgInfo
(
"conflict db update, ignore this update, dbFName:%s, dbId:%"
PRIx64
,
dbFName
,
dbId
);
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
}
SDBVgInfo
*
vgInfo
=
NULL
;
CTG_ERR_RET
(
ctgWAcquireVgInfo
(
pCtg
,
dbCache
));
if
(
dbCache
->
vgInfo
)
{
if
(
dbInfo
->
vgVersion
<
dbCache
->
vgInfo
->
vgVersion
)
{
ctgDebug
(
"db vgVersion is old, dbFName:%s, vgVersion:%d, currentVersion:%d"
,
dbFName
,
dbInfo
->
vgVersion
,
dbCache
->
vgInfo
->
vgVersion
);
ctgWReleaseVgInfo
(
dbCache
);
return
TSDB_CODE_SUCCESS
;
CTG_ERR_RET
(
ctgMetaRentUpdate
(
&
pCtg
->
stbRent
,
&
metaRent
,
metaRent
.
suid
,
sizeof
(
SSTableVersion
),
ctgStbVersionSortCompare
,
ctgStbVersionSearchCompare
));
}
if
(
dbInfo
->
vgVersion
==
dbCache
->
vgInfo
->
vgVersion
&&
dbInfo
->
numOfTable
==
dbCache
->
vgInfo
->
numOfTable
)
{
ctgDebug
(
"db %s,%"
PRIx64
" stb %s,%"
PRIx64
" sver %d tver %d smaVer %d updated to stbRent"
,
ctgDebug
(
"no new db vgVersion or numOfTable, dbFName:%s, vgVersion:%d, numOfTable:%d"
,
dbFName
,
dbInfo
->
vgVersion
,
dbInfo
->
numOfTable
);
dbFName
,
dbId
,
tbName
,
suid
,
metaRent
.
sversion
,
metaRent
.
tversion
,
metaRent
.
smaVer
);
ctgWReleaseVgInfo
(
dbCache
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
ctgFreeVgInfo
(
dbCache
->
vgInfo
);
}
dbCache
->
vgInfo
=
dbInfo
;
*
pDbInfo
=
NULL
;
ctgDebug
(
"db vgInfo updated, dbFName:%s, vgVersion:%d, dbId:%"
PRIx64
,
dbFName
,
vgVersion
.
vgVersion
,
vgVersion
.
dbId
);
ctgWReleaseVgInfo
(
dbCache
);
dbCache
=
NULL
;
strncpy
(
vgVersion
.
dbFName
,
dbFName
,
sizeof
(
vgVersion
.
dbFName
));
CTG_ERR_RET
(
ctgMetaRentUpdate
(
&
pCtg
->
dbRent
,
&
vgVersion
,
vgVersion
.
dbId
,
sizeof
(
SDbVgVersion
),
ctgDbVgVersionSortCompare
,
ctgDbVgVersionSearchCompare
));
CTG_RET
(
code
);
}
}
int32_t
ctgWriteTbMetaToCache
(
SCatalog
*
pCtg
,
SCtgDBCache
*
dbCache
,
char
*
dbFName
,
uint64_t
dbId
,
char
*
tbName
,
STableMeta
*
meta
,
int32_t
metaSize
)
{
int32_t
ctgWriteTbMetaToCache
(
SCatalog
*
pCtg
,
SCtgDBCache
*
dbCache
,
char
*
dbFName
,
uint64_t
dbId
,
char
*
tbName
,
STableMeta
*
meta
,
int32_t
metaSize
)
{
SCtgTbMetaCache
*
tbCache
=
&
dbCache
->
tbCache
;
if
(
NULL
==
dbCache
->
tbCache
||
NULL
==
dbCache
->
stbCache
)
{
taosMemoryFree
(
meta
);
CTG_LOCK
(
CTG_READ
,
&
tbCache
->
metaLock
);
if
(
dbCache
->
deleted
||
NULL
==
tbCache
->
metaCache
||
NULL
==
tbCache
->
stbCache
)
{
CTG_UNLOCK
(
CTG_READ
,
&
tbCache
->
metaLock
);
ctgError
(
"db is dropping, dbId:%"
PRIx64
,
dbCache
->
dbId
);
ctgError
(
"db is dropping, dbId:%"
PRIx64
,
dbCache
->
dbId
);
CTG_ERR_RET
(
TSDB_CODE_CTG_DB_DROPPED
);
CTG_ERR_RET
(
TSDB_CODE_CTG_DB_DROPPED
);
}
}
bool
isStb
=
meta
->
tableType
==
TSDB_SUPER_TABLE
;
SCtgTbCache
*
pCache
=
taosHashGet
(
dbCache
->
tbCache
,
tbName
,
strlen
(
tbName
));
STableMeta
*
orig
=
(
pCache
?
pCache
->
pMeta
:
NULL
);
int8_t
origType
=
0
;
int8_t
origType
=
0
;
uint64_t
origSuid
=
0
;
uint64_t
origSuid
=
0
;
bool
isStb
=
meta
->
tableType
==
TSDB_SUPER_TABLE
;
STableMeta
*
orig
=
taosHashGet
(
tbCache
->
metaCache
,
tbName
,
strlen
(
tbName
));
if
(
orig
)
{
if
(
orig
)
{
origType
=
orig
->
tableType
;
origType
=
orig
->
tableType
;
if
(
origType
==
meta
->
tableType
&&
orig
->
uid
==
meta
->
uid
&&
orig
->
sversion
>=
meta
->
sversion
&&
orig
->
tversion
>=
meta
->
tversion
)
{
if
(
origType
==
meta
->
tableType
&&
orig
->
uid
==
meta
->
uid
&&
orig
->
sversion
>=
meta
->
sversion
&&
orig
->
tversion
>=
meta
->
tversion
)
{
CTG_UNLOCK
(
CTG_READ
,
&
tbCache
->
metaLock
);
taosMemoryFree
(
meta
);
ctgDebug
(
"ignore table %s meta update"
,
tbName
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
if
(
origType
==
TSDB_SUPER_TABLE
)
{
if
(
origType
==
TSDB_SUPER_TABLE
)
{
CTG_LOCK
(
CTG_WRITE
,
&
tbCache
->
stbLock
);
if
(
taosHashRemove
(
dbCache
->
stbCache
,
&
orig
->
suid
,
sizeof
(
orig
->
suid
)))
{
if
(
taosHashRemove
(
tbCache
->
stbCache
,
&
orig
->
suid
,
sizeof
(
orig
->
suid
)))
{
ctgError
(
"stb not exist in stbCache, dbFName:%s, stb:%s, suid:%"
PRIx64
,
dbFName
,
tbName
,
orig
->
suid
);
ctgError
(
"stb not exist in stbCache, dbFName:%s, stb:%s, suid:%"
PRIx64
,
dbFName
,
tbName
,
orig
->
suid
);
}
else
{
}
else
{
CTG_CACHE_STAT_DEC
(
stblNum
,
1
);
CTG_CACHE_STAT_DEC
(
stblNum
,
1
);
}
CTG_UNLOCK
(
CTG_WRITE
,
&
tbCache
->
stbLock
);
ctgDebug
(
"stb removed from stbCache, dbFName:%s, stb:%s, suid:%"
PRIx64
,
dbFName
,
tbName
,
orig
->
suid
);
ctgDebug
(
"stb removed from stbCache, dbFName:%s, stb:%s, suid:%"
PRIx64
,
dbFName
,
tbName
,
orig
->
suid
);
}
ctgMetaRentRemove
(
&
pCtg
->
stbRent
,
orig
->
suid
,
ctgStbVersionSortCompare
,
ctgStbVersionSearchCompare
);
origSuid
=
orig
->
suid
;
origSuid
=
orig
->
suid
;
}
}
}
}
if
(
isStb
)
{
if
(
NULL
==
pCache
)
{
CTG_LOCK
(
CTG_WRITE
,
&
tbCache
->
stbLock
)
;
SCtgTbCache
cache
=
{
0
}
;
}
cache
.
pMeta
=
meta
;
if
(
taosHashPut
(
dbCache
->
tbCache
,
tbName
,
strlen
(
tbName
),
&
cache
,
sizeof
(
SCtgTbCache
))
!=
0
)
{
if
(
taosHashPut
(
tbCache
->
metaCache
,
tbName
,
strlen
(
tbName
),
meta
,
metaSize
)
!=
0
)
{
taosMemoryFree
(
meta
);
if
(
isStb
)
{
ctgError
(
"taosHashPut new tbCache failed, dbFName:%s, tbName:%s, tbType:%d"
,
dbFName
,
tbName
,
meta
->
tableType
);
CTG_
UNLOCK
(
CTG_WRITE
,
&
tbCache
->
stbLock
);
CTG_
ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
}
CTG_UNLOCK
(
CTG_READ
,
&
tbCache
->
metaLock
);
pCache
=
taosHashGet
(
dbCache
->
tbCache
,
tbName
,
strlen
(
tbName
));
ctgError
(
"taosHashPut tbmeta to cache failed, dbFName:%s, tbName:%s, tbType:%d"
,
dbFName
,
tbName
,
meta
->
tableType
);
}
else
{
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
taosMemoryFree
(
pCache
->
pMeta
);
pCache
->
pMeta
=
meta
;
}
}
if
(
NULL
==
orig
)
{
if
(
NULL
==
orig
)
{
...
@@ -1262,30 +1403,71 @@ int32_t ctgWriteTbMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFNam
...
@@ -1262,30 +1403,71 @@ int32_t ctgWriteTbMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFNam
ctgdShowTableMeta
(
pCtg
,
tbName
,
meta
);
ctgdShowTableMeta
(
pCtg
,
tbName
,
meta
);
if
(
!
isStb
)
{
if
(
!
isStb
)
{
CTG_UNLOCK
(
CTG_READ
,
&
tbCache
->
metaLock
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
STableMeta
*
tbMeta
=
taosHashGet
(
tbCache
->
metaCache
,
tbName
,
strlen
(
tbName
));
if
(
origSuid
!=
meta
->
suid
&&
taosHashPut
(
dbCache
->
stbCache
,
&
meta
->
suid
,
sizeof
(
meta
->
suid
),
tbName
,
strlen
(
tbName
)
+
1
)
!=
0
)
{
if
(
taosHashPut
(
tbCache
->
stbCache
,
&
meta
->
suid
,
sizeof
(
meta
->
suid
),
&
tbMeta
,
POINTER_BYTES
)
!=
0
)
{
ctgError
(
"taosHashPut to stable cache failed, suid:%"
PRIx64
,
meta
->
suid
);
CTG_UNLOCK
(
CTG_WRITE
,
&
tbCache
->
stbLock
);
CTG_UNLOCK
(
CTG_READ
,
&
tbCache
->
metaLock
);
ctgError
(
"taosHashPut stable to stable cache failed, suid:%"
PRIx64
,
meta
->
suid
);
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
}
CTG_CACHE_STAT_INC
(
stblNum
,
1
);
CTG_CACHE_STAT_INC
(
stblNum
,
1
);
CTG_UNLOCK
(
CTG_WRITE
,
&
tbCache
->
stbLock
);
ctgDebug
(
"stb %"
PRIx64
" updated to cache, dbFName:%s, tbName:%s, tbType:%d"
,
meta
->
suid
,
dbFName
,
tbName
,
meta
->
tableType
);
CTG_
UNLOCK
(
CTG_READ
,
&
tbCache
->
metaLock
);
CTG_
ERR_RET
(
ctgUpdateRentStbVersion
(
pCtg
,
dbFName
,
tbName
,
dbId
,
meta
->
suid
,
pCache
)
);
ctgDebug
(
"stb updated to stbCache, dbFName:%s, tbName:%s, tbType:%d"
,
dbFName
,
tbName
,
meta
->
tableType
);
return
TSDB_CODE_SUCCESS
;
}
SSTableMetaVersion
metaRent
=
{.
dbId
=
dbId
,
.
suid
=
meta
->
suid
,
.
sversion
=
meta
->
sversion
,
.
tversion
=
meta
->
tversion
};
int32_t
ctgWriteTbIndexToCache
(
SCatalog
*
pCtg
,
SCtgDBCache
*
dbCache
,
char
*
dbFName
,
char
*
tbName
,
STableIndex
**
index
)
{
strcpy
(
metaRent
.
dbFName
,
dbFName
);
if
(
NULL
==
dbCache
->
tbCache
)
{
strcpy
(
metaRent
.
stbName
,
tbName
);
ctgFreeSTableIndex
(
*
index
);
CTG_ERR_RET
(
ctgMetaRentAdd
(
&
pCtg
->
stbRent
,
&
metaRent
,
metaRent
.
suid
,
sizeof
(
SSTableMetaVersion
)));
taosMemoryFreeClear
(
*
index
);
ctgError
(
"db is dropping, dbId:%"
PRIx64
,
dbCache
->
dbId
);
CTG_ERR_RET
(
TSDB_CODE_CTG_DB_DROPPED
);
}
STableIndex
*
pIndex
=
*
index
;
uint64_t
suid
=
pIndex
->
suid
;
SCtgTbCache
*
pCache
=
taosHashGet
(
dbCache
->
tbCache
,
tbName
,
strlen
(
tbName
));
if
(
NULL
==
pCache
)
{
SCtgTbCache
cache
=
{
0
};
cache
.
pIndex
=
pIndex
;
if
(
taosHashPut
(
dbCache
->
tbCache
,
tbName
,
strlen
(
tbName
),
&
cache
,
sizeof
(
cache
))
!=
0
)
{
ctgFreeSTableIndex
(
*
index
);
taosMemoryFreeClear
(
*
index
);
ctgError
(
"taosHashPut new tbCache failed, tbName:%s"
,
tbName
);
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
*
index
=
NULL
;
ctgDebug
(
"table %s index updated to cache, ver:%d, num:%d"
,
tbName
,
pIndex
->
version
,
(
int32_t
)
taosArrayGetSize
(
pIndex
->
pIndex
));
if
(
suid
)
{
CTG_ERR_RET
(
ctgUpdateRentStbVersion
(
pCtg
,
dbFName
,
tbName
,
dbCache
->
dbId
,
pIndex
->
suid
,
&
cache
));
}
return
TSDB_CODE_SUCCESS
;
}
if
(
pCache
->
pIndex
)
{
if
(
0
==
suid
)
{
suid
=
pCache
->
pIndex
->
suid
;
}
taosArrayDestroyEx
(
pCache
->
pIndex
->
pIndex
,
tFreeSTableIndexInfo
);
taosMemoryFreeClear
(
pCache
->
pIndex
);
}
pCache
->
pIndex
=
pIndex
;
*
index
=
NULL
;
ctgDebug
(
"table %s index updated to cache, ver:%d, num:%d"
,
tbName
,
pIndex
->
version
,
(
int32_t
)
taosArrayGetSize
(
pIndex
->
pIndex
));
if
(
suid
)
{
CTG_ERR_RET
(
ctgUpdateRentStbVersion
(
pCtg
,
dbFName
,
tbName
,
dbCache
->
dbId
,
suid
,
pCache
));
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -1305,12 +1487,67 @@ _return:
...
@@ -1305,12 +1487,67 @@ _return:
CTG_RET
(
code
);
CTG_RET
(
code
);
}
}
int32_t
ctgOpUpdateVgroup
(
SCtgCacheOperation
*
operation
)
{
int32_t
ctgOpUpdateVgroup
(
SCtgCacheOperation
*
operation
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
SCtgUpdateVgMsg
*
msg
=
operation
->
data
;
SCtgUpdateVgMsg
*
msg
=
operation
->
data
;
SDBVgInfo
*
dbInfo
=
msg
->
dbInfo
;
char
*
dbFName
=
msg
->
dbFName
;
SCatalog
*
pCtg
=
msg
->
pCtg
;
if
(
NULL
==
dbInfo
->
vgHash
)
{
return
TSDB_CODE_SUCCESS
;
}
if
(
dbInfo
->
vgVersion
<
0
||
taosHashGetSize
(
dbInfo
->
vgHash
)
<=
0
)
{
ctgError
(
"invalid db vgInfo, dbFName:%s, vgHash:%p, vgVersion:%d, vgHashSize:%d"
,
dbFName
,
dbInfo
->
vgHash
,
dbInfo
->
vgVersion
,
taosHashGetSize
(
dbInfo
->
vgHash
));
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
bool
newAdded
=
false
;
SDbVgVersion
vgVersion
=
{.
dbId
=
msg
->
dbId
,
.
vgVersion
=
dbInfo
->
vgVersion
,
.
numOfTable
=
dbInfo
->
numOfTable
};
SCtgDBCache
*
dbCache
=
NULL
;
CTG_ERR_RET
(
ctgGetAddDBCache
(
msg
->
pCtg
,
dbFName
,
msg
->
dbId
,
&
dbCache
));
if
(
NULL
==
dbCache
)
{
ctgInfo
(
"conflict db update, ignore this update, dbFName:%s, dbId:%"
PRIx64
,
dbFName
,
msg
->
dbId
);
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
}
SCtgVgCache
*
vgCache
=
&
dbCache
->
vgCache
;
CTG_ERR_RET
(
ctgWLockVgInfo
(
msg
->
pCtg
,
dbCache
));
if
(
vgCache
->
vgInfo
)
{
SDBVgInfo
*
vgInfo
=
vgCache
->
vgInfo
;
if
(
dbInfo
->
vgVersion
<
vgInfo
->
vgVersion
)
{
ctgDebug
(
"db vgVer is old, dbFName:%s, vgVer:%d, curVer:%d"
,
dbFName
,
dbInfo
->
vgVersion
,
vgInfo
->
vgVersion
);
ctgWUnlockVgInfo
(
dbCache
);
return
TSDB_CODE_SUCCESS
;
}
if
(
dbInfo
->
vgVersion
==
vgInfo
->
vgVersion
&&
dbInfo
->
numOfTable
==
vgInfo
->
numOfTable
)
{
ctgDebug
(
"no new db vgVer or numOfTable, dbFName:%s, vgVer:%d, numOfTable:%d"
,
dbFName
,
dbInfo
->
vgVersion
,
dbInfo
->
numOfTable
);
ctgWUnlockVgInfo
(
dbCache
);
return
TSDB_CODE_SUCCESS
;
}
ctgFreeVgInfo
(
vgInfo
);
}
vgCache
->
vgInfo
=
dbInfo
;
msg
->
dbInfo
=
NULL
;
CTG_ERR_JRET
(
ctgWriteDBVgInfoToCache
(
msg
->
pCtg
,
msg
->
dbFName
,
msg
->
dbId
,
&
msg
->
dbInfo
));
ctgDebug
(
"db vgInfo updated, dbFName:%s, vgVer:%d, dbId:%"
PRIx64
,
dbFName
,
vgVersion
.
vgVersion
,
vgVersion
.
dbId
);
ctgWUnlockVgInfo
(
dbCache
);
dbCache
=
NULL
;
strncpy
(
vgVersion
.
dbFName
,
dbFName
,
sizeof
(
vgVersion
.
dbFName
));
CTG_ERR_RET
(
ctgMetaRentUpdate
(
&
msg
->
pCtg
->
dbRent
,
&
vgVersion
,
vgVersion
.
dbId
,
sizeof
(
SDbVgVersion
),
ctgDbVgVersionSortCompare
,
ctgDbVgVersionSearchCompare
));
_return:
_return:
...
@@ -1356,14 +1593,14 @@ int32_t ctgOpDropDbVgroup(SCtgCacheOperation *operation) {
...
@@ -1356,14 +1593,14 @@ int32_t ctgOpDropDbVgroup(SCtgCacheOperation *operation) {
goto
_return
;
goto
_return
;
}
}
CTG_ERR_RET
(
ctgW
Acquire
VgInfo
(
pCtg
,
dbCache
));
CTG_ERR_RET
(
ctgW
Lock
VgInfo
(
pCtg
,
dbCache
));
ctgFreeVgInfo
(
dbCache
->
vgInfo
);
ctgFreeVgInfo
(
dbCache
->
vg
Cache
.
vg
Info
);
dbCache
->
vgInfo
=
NULL
;
dbCache
->
vg
Cache
.
vg
Info
=
NULL
;
ctgDebug
(
"db vgInfo removed, dbFName:%s"
,
msg
->
dbFName
);
ctgDebug
(
"db vgInfo removed, dbFName:%s"
,
msg
->
dbFName
);
ctgW
Release
VgInfo
(
dbCache
);
ctgW
Unlock
VgInfo
(
dbCache
);
_return:
_return:
...
@@ -1375,42 +1612,47 @@ _return:
...
@@ -1375,42 +1612,47 @@ _return:
int32_t
ctgOpUpdateTbMeta
(
SCtgCacheOperation
*
operation
)
{
int32_t
ctgOpUpdateTbMeta
(
SCtgCacheOperation
*
operation
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
SCtgUpdateTb
l
Msg
*
msg
=
operation
->
data
;
SCtgUpdateTb
Meta
Msg
*
msg
=
operation
->
data
;
SCatalog
*
pCtg
=
msg
->
pCtg
;
SCatalog
*
pCtg
=
msg
->
pCtg
;
STableMetaOutput
*
output
=
msg
->
output
;
STableMetaOutput
*
pMeta
=
msg
->
pMeta
;
SCtgDBCache
*
dbCache
=
NULL
;
SCtgDBCache
*
dbCache
=
NULL
;
if
((
!
CTG_IS_META_CTABLE
(
output
->
metaType
))
&&
NULL
==
output
->
tbMeta
)
{
if
((
!
CTG_IS_META_CTABLE
(
pMeta
->
metaType
))
&&
NULL
==
pMeta
->
tbMeta
)
{
ctgError
(
"no valid tbmeta got from meta rsp, dbFName:%s, tbName:%s"
,
output
->
dbFName
,
output
->
tbName
);
ctgError
(
"no valid tbmeta got from meta rsp, dbFName:%s, tbName:%s"
,
pMeta
->
dbFName
,
pMeta
->
tbName
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
}
}
if
(
CTG_IS_META_BOTH
(
output
->
metaType
)
&&
TSDB_SUPER_TABLE
!=
output
->
tbMeta
->
tableType
)
{
if
(
CTG_IS_META_BOTH
(
pMeta
->
metaType
)
&&
TSDB_SUPER_TABLE
!=
pMeta
->
tbMeta
->
tableType
)
{
ctgError
(
"table type error, expected:%d, actual:%d"
,
TSDB_SUPER_TABLE
,
output
->
tbMeta
->
tableType
);
ctgError
(
"table type error, expected:%d, actual:%d"
,
TSDB_SUPER_TABLE
,
pMeta
->
tbMeta
->
tableType
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
}
}
CTG_ERR_JRET
(
ctgGetAddDBCache
(
pCtg
,
output
->
dbFName
,
output
->
dbId
,
&
dbCache
));
CTG_ERR_JRET
(
ctgGetAddDBCache
(
pCtg
,
pMeta
->
dbFName
,
pMeta
->
dbId
,
&
dbCache
));
if
(
NULL
==
dbCache
)
{
if
(
NULL
==
dbCache
)
{
ctgInfo
(
"conflict db update, ignore this update, dbFName:%s, dbId:%"
PRIx64
,
output
->
dbFName
,
output
->
dbId
);
ctgInfo
(
"conflict db update, ignore this update, dbFName:%s, dbId:%"
PRIx64
,
pMeta
->
dbFName
,
pMeta
->
dbId
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
}
}
if
(
CTG_IS_META_TABLE
(
output
->
metaType
)
||
CTG_IS_META_BOTH
(
output
->
metaType
))
{
if
(
CTG_IS_META_TABLE
(
pMeta
->
metaType
)
||
CTG_IS_META_BOTH
(
pMeta
->
metaType
))
{
int32_t
metaSize
=
CTG_META_SIZE
(
output
->
tbMeta
);
int32_t
metaSize
=
CTG_META_SIZE
(
pMeta
->
tbMeta
);
CTG_ERR_JRET
(
ctgWriteTbMetaToCache
(
pCtg
,
dbCache
,
pMeta
->
dbFName
,
pMeta
->
dbId
,
pMeta
->
tbName
,
pMeta
->
tbMeta
,
metaSize
));
CTG_ERR_JRET
(
ctgWriteTbMetaToCache
(
pCtg
,
dbCache
,
output
->
dbFName
,
output
->
dbId
,
output
->
tbName
,
output
->
tbMeta
,
metaSize
))
;
pMeta
->
tbMeta
=
NULL
;
}
}
if
(
CTG_IS_META_CTABLE
(
output
->
metaType
)
||
CTG_IS_META_BOTH
(
output
->
metaType
))
{
if
(
CTG_IS_META_CTABLE
(
pMeta
->
metaType
)
||
CTG_IS_META_BOTH
(
pMeta
->
metaType
))
{
CTG_ERR_JRET
(
ctgWriteTbMetaToCache
(
pCtg
,
dbCache
,
output
->
dbFName
,
output
->
dbId
,
output
->
ctbName
,
(
STableMeta
*
)
&
output
->
ctbMeta
,
sizeof
(
output
->
ctbMeta
)));
SCTableMeta
*
ctbMeta
=
taosMemoryMalloc
(
sizeof
(
SCTableMeta
));
if
(
NULL
==
ctbMeta
)
{
CTG_ERR_JRET
(
TSDB_CODE_OUT_OF_MEMORY
);
}
memcpy
(
ctbMeta
,
&
pMeta
->
ctbMeta
,
sizeof
(
SCTableMeta
));
CTG_ERR_JRET
(
ctgWriteTbMetaToCache
(
pCtg
,
dbCache
,
pMeta
->
dbFName
,
pMeta
->
dbId
,
pMeta
->
ctbName
,
(
STableMeta
*
)
ctbMeta
,
sizeof
(
SCTableMeta
)));
}
}
_return:
_return:
if
(
output
)
{
if
(
pMeta
)
{
taosMemoryFreeClear
(
output
->
tbMeta
);
taosMemoryFreeClear
(
pMeta
->
tbMeta
);
taosMemoryFreeClear
(
output
);
taosMemoryFreeClear
(
pMeta
);
}
}
taosMemoryFreeClear
(
msg
);
taosMemoryFreeClear
(
msg
);
...
@@ -1435,22 +1677,17 @@ int32_t ctgOpDropStbMeta(SCtgCacheOperation *operation) {
...
@@ -1435,22 +1677,17 @@ int32_t ctgOpDropStbMeta(SCtgCacheOperation *operation) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
CTG_LOCK
(
CTG_WRITE
,
&
dbCache
->
tbCache
.
stbLock
);
if
(
taosHashRemove
(
dbCache
->
stbCache
,
&
msg
->
suid
,
sizeof
(
msg
->
suid
)))
{
if
(
taosHashRemove
(
dbCache
->
tbCache
.
stbCache
,
&
msg
->
suid
,
sizeof
(
msg
->
suid
)))
{
ctgDebug
(
"stb not exist in stbCache, may be removed, dbFName:%s, stb:%s, suid:%"
PRIx64
,
msg
->
dbFName
,
msg
->
stbName
,
msg
->
suid
);
ctgDebug
(
"stb not exist in stbCache, may be removed, dbFName:%s, stb:%s, suid:%"
PRIx64
,
msg
->
dbFName
,
msg
->
stbName
,
msg
->
suid
);
}
else
{
}
else
{
CTG_CACHE_STAT_DEC
(
stblNum
,
1
);
CTG_CACHE_STAT_DEC
(
stblNum
,
1
);
}
}
CTG_LOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
metaLock
);
if
(
taosHashRemove
(
dbCache
->
tbCache
,
msg
->
stbName
,
strlen
(
msg
->
stbName
)))
{
if
(
taosHashRemove
(
dbCache
->
tbCache
.
metaCache
,
msg
->
stbName
,
strlen
(
msg
->
stbName
)))
{
ctgError
(
"stb not exist in cache, dbFName:%s, stb:%s, suid:%"
PRIx64
,
msg
->
dbFName
,
msg
->
stbName
,
msg
->
suid
);
ctgError
(
"stb not exist in cache, dbFName:%s, stb:%s, suid:%"
PRIx64
,
msg
->
dbFName
,
msg
->
stbName
,
msg
->
suid
);
}
else
{
}
else
{
CTG_CACHE_STAT_DEC
(
tblNum
,
1
);
CTG_CACHE_STAT_DEC
(
tblNum
,
1
);
}
}
CTG_UNLOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
metaLock
);
CTG_UNLOCK
(
CTG_WRITE
,
&
dbCache
->
tbCache
.
stbLock
);
ctgInfo
(
"stb removed from cache, dbFName:%s, stbName:%s, suid:%"
PRIx64
,
msg
->
dbFName
,
msg
->
stbName
,
msg
->
suid
);
ctgInfo
(
"stb removed from cache, dbFName:%s, stbName:%s, suid:%"
PRIx64
,
msg
->
dbFName
,
msg
->
stbName
,
msg
->
suid
);
...
@@ -1477,21 +1714,18 @@ int32_t ctgOpDropTbMeta(SCtgCacheOperation *operation) {
...
@@ -1477,21 +1714,18 @@ int32_t ctgOpDropTbMeta(SCtgCacheOperation *operation) {
}
}
if
(
dbCache
->
dbId
!=
msg
->
dbId
)
{
if
(
dbCache
->
dbId
!=
msg
->
dbId
)
{
ctgDebug
(
"dbId
already modified, dbFName:%s, current:%"
PRIx64
", dbId:%"
PRIx64
", tbName:%s"
,
msg
->
dbFName
,
dbCache
->
dbId
,
msg
->
dbId
,
msg
->
tbName
);
ctgDebug
(
"dbId
%"
PRIx64
" not match with curId %"
PRIx64
", dbFName:%s, tbName:%s"
,
msg
->
dbId
,
dbCache
->
dbId
,
msg
->
dbFName
,
msg
->
tbName
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
CTG_LOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
metaLock
);
if
(
taosHashRemove
(
dbCache
->
tbCache
,
msg
->
tbName
,
strlen
(
msg
->
tbName
)))
{
if
(
taosHashRemove
(
dbCache
->
tbCache
.
metaCache
,
msg
->
tbName
,
strlen
(
msg
->
tbName
)))
{
ctgError
(
"tb %s not exist in cache, dbFName:%s"
,
msg
->
tbName
,
msg
->
dbFName
);
CTG_UNLOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
metaLock
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
ctgError
(
"stb not exist in cache, dbFName:%s, tbName:%s"
,
msg
->
dbFName
,
msg
->
tbName
);
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
}
else
{
}
else
{
CTG_CACHE_STAT_DEC
(
tblNum
,
1
);
CTG_CACHE_STAT_DEC
(
tblNum
,
1
);
}
}
CTG_UNLOCK
(
CTG_READ
,
&
dbCache
->
tbCache
.
metaLock
);
ctg
Info
(
"table removed from cache, dbFName:%s, tbName:%s"
,
msg
->
dbFName
,
msg
->
tb
Name
);
ctg
Debug
(
"table %s removed from cache, dbFName:%s"
,
msg
->
tbName
,
msg
->
dbF
Name
);
_return:
_return:
...
@@ -1553,7 +1787,6 @@ int32_t ctgOpUpdateUser(SCtgCacheOperation *operation) {
...
@@ -1553,7 +1787,6 @@ int32_t ctgOpUpdateUser(SCtgCacheOperation *operation) {
_return:
_return:
taosHashCleanup
(
msg
->
userAuth
.
createdDbs
);
taosHashCleanup
(
msg
->
userAuth
.
createdDbs
);
taosHashCleanup
(
msg
->
userAuth
.
readDbs
);
taosHashCleanup
(
msg
->
userAuth
.
readDbs
);
taosHashCleanup
(
msg
->
userAuth
.
writeDbs
);
taosHashCleanup
(
msg
->
userAuth
.
writeDbs
);
...
@@ -1569,24 +1802,22 @@ int32_t ctgOpUpdateEpset(SCtgCacheOperation *operation) {
...
@@ -1569,24 +1802,22 @@ int32_t ctgOpUpdateEpset(SCtgCacheOperation *operation) {
SCatalog
*
pCtg
=
msg
->
pCtg
;
SCatalog
*
pCtg
=
msg
->
pCtg
;
SCtgDBCache
*
dbCache
=
NULL
;
SCtgDBCache
*
dbCache
=
NULL
;
CTG_ERR_
RET
(
ctgAcquire
DBCache
(
pCtg
,
msg
->
dbFName
,
&
dbCache
));
CTG_ERR_
JRET
(
ctgGet
DBCache
(
pCtg
,
msg
->
dbFName
,
&
dbCache
));
if
(
NULL
==
dbCache
)
{
if
(
NULL
==
dbCache
)
{
ctgDebug
(
"db %s not exist, ignore epset update"
,
msg
->
dbFName
);
ctgDebug
(
"db %s not exist, ignore epset update"
,
msg
->
dbFName
);
goto
_return
;
goto
_return
;
}
}
SDBVgInfo
*
vgInfo
=
NULL
;
CTG_ERR_JRET
(
ctgWLockVgInfo
(
pCtg
,
dbCache
));
CTG_ERR_RET
(
ctgWAcquireVgInfo
(
pCtg
,
dbCache
));
if
(
NULL
==
dbCache
->
vgInfo
)
{
SDBVgInfo
*
vgInfo
=
dbCache
->
vgCache
.
vgInfo
;
ctgWReleaseVgInfo
(
dbCache
);
if
(
NULL
==
vgInfo
)
{
ctgDebug
(
"vgroup in db %s not cached, ignore epset update"
,
msg
->
dbFName
);
ctgDebug
(
"vgroup in db %s not cached, ignore epset update"
,
msg
->
dbFName
);
goto
_return
;
goto
_return
;
}
}
SVgroupInfo
*
pInfo
=
taosHashGet
(
dbCache
->
vgInfo
->
vgHash
,
&
msg
->
vgId
,
sizeof
(
msg
->
vgId
));
SVgroupInfo
*
pInfo
=
taosHashGet
(
vgInfo
->
vgHash
,
&
msg
->
vgId
,
sizeof
(
msg
->
vgId
));
if
(
NULL
==
pInfo
)
{
if
(
NULL
==
pInfo
)
{
ctgWReleaseVgInfo
(
dbCache
);
ctgDebug
(
"no vgroup %d in db %s, ignore epset update"
,
msg
->
vgId
,
msg
->
dbFName
);
ctgDebug
(
"no vgroup %d in db %s, ignore epset update"
,
msg
->
vgId
,
msg
->
dbFName
);
goto
_return
;
goto
_return
;
}
}
...
@@ -1599,12 +1830,66 @@ int32_t ctgOpUpdateEpset(SCtgCacheOperation *operation) {
...
@@ -1599,12 +1830,66 @@ int32_t ctgOpUpdateEpset(SCtgCacheOperation *operation) {
pInfo
->
epSet
=
msg
->
epSet
;
pInfo
->
epSet
=
msg
->
epSet
;
ctgWReleaseVgInfo
(
dbCache
);
_return:
_return:
if
(
dbCache
)
{
if
(
dbCache
)
{
ctgReleaseDBCache
(
msg
->
pCtg
,
dbCache
);
ctgWUnlockVgInfo
(
dbCache
);
}
taosMemoryFreeClear
(
msg
);
CTG_RET
(
code
);
}
int32_t
ctgOpUpdateTbIndex
(
SCtgCacheOperation
*
operation
)
{
int32_t
code
=
0
;
SCtgUpdateTbIndexMsg
*
msg
=
operation
->
data
;
SCatalog
*
pCtg
=
msg
->
pCtg
;
STableIndex
*
pIndex
=
msg
->
pIndex
;
SCtgDBCache
*
dbCache
=
NULL
;
CTG_ERR_JRET
(
ctgGetAddDBCache
(
pCtg
,
pIndex
->
dbFName
,
0
,
&
dbCache
));
CTG_ERR_JRET
(
ctgWriteTbIndexToCache
(
pCtg
,
dbCache
,
pIndex
->
dbFName
,
pIndex
->
tbName
,
&
pIndex
));
_return:
if
(
pIndex
)
{
taosArrayDestroyEx
(
pIndex
->
pIndex
,
tFreeSTableIndexInfo
);
taosMemoryFreeClear
(
pIndex
);
}
taosMemoryFreeClear
(
msg
);
CTG_RET
(
code
);
}
int32_t
ctgOpDropTbIndex
(
SCtgCacheOperation
*
operation
)
{
int32_t
code
=
0
;
SCtgDropTbIndexMsg
*
msg
=
operation
->
data
;
SCatalog
*
pCtg
=
msg
->
pCtg
;
SCtgDBCache
*
dbCache
=
NULL
;
CTG_ERR_JRET
(
ctgGetDBCache
(
pCtg
,
msg
->
dbFName
,
&
dbCache
));
if
(
NULL
==
dbCache
)
{
return
TSDB_CODE_SUCCESS
;
}
STableIndex
*
pIndex
=
taosMemoryCalloc
(
1
,
sizeof
(
STableIndex
));
if
(
NULL
==
pIndex
)
{
CTG_ERR_JRET
(
TSDB_CODE_OUT_OF_MEMORY
);
}
strcpy
(
pIndex
->
tbName
,
msg
->
tbName
);
strcpy
(
pIndex
->
dbFName
,
msg
->
dbFName
);
pIndex
->
version
=
-
1
;
CTG_ERR_JRET
(
ctgWriteTbIndexToCache
(
pCtg
,
dbCache
,
pIndex
->
dbFName
,
pIndex
->
tbName
,
&
pIndex
));
_return:
if
(
pIndex
)
{
taosArrayDestroyEx
(
pIndex
->
pIndex
,
tFreeSTableIndexInfo
);
taosMemoryFreeClear
(
pIndex
);
}
}
taosMemoryFreeClear
(
msg
);
taosMemoryFreeClear
(
msg
);
...
...
source/libs/catalog/src/ctgDbg.c
浏览文件 @
2861534a
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
#include "catalogInt.h"
#include "catalogInt.h"
extern
SCatalogMgmt
gCtgMgmt
;
extern
SCatalogMgmt
gCtgMgmt
;
SCtgDebug
gCTGDebug
=
{
.
apiEnable
=
true
};
SCtgDebug
gCTGDebug
=
{
0
};
void
ctgdUserCallback
(
SMetaData
*
pResult
,
void
*
param
,
int32_t
code
)
{
void
ctgdUserCallback
(
SMetaData
*
pResult
,
void
*
param
,
int32_t
code
)
{
ASSERT
(
*
(
int32_t
*
)
param
==
1
);
ASSERT
(
*
(
int32_t
*
)
param
==
1
);
...
@@ -266,11 +266,11 @@ int32_t ctgdGetStatNum(char *option, void *res) {
...
@@ -266,11 +266,11 @@ int32_t ctgdGetStatNum(char *option, void *res) {
}
}
int32_t
ctgdGetTbMetaNum
(
SCtgDBCache
*
dbCache
)
{
int32_t
ctgdGetTbMetaNum
(
SCtgDBCache
*
dbCache
)
{
return
dbCache
->
tbCache
.
metaCache
?
(
int32_t
)
taosHashGetSize
(
dbCache
->
tbCache
.
meta
Cache
)
:
0
;
return
dbCache
->
tbCache
?
(
int32_t
)
taosHashGetSize
(
dbCache
->
tb
Cache
)
:
0
;
}
}
int32_t
ctgdGetStbNum
(
SCtgDBCache
*
dbCache
)
{
int32_t
ctgdGetStbNum
(
SCtgDBCache
*
dbCache
)
{
return
dbCache
->
tbCache
.
stbCache
?
(
int32_t
)
taosHashGetSize
(
dbCache
->
tbCache
.
stbCache
)
:
0
;
return
dbCache
->
stbCache
?
(
int32_t
)
taosHashGetSize
(
dbCache
->
stbCache
)
:
0
;
}
}
int32_t
ctgdGetRentNum
(
SCtgRentMgmt
*
rent
)
{
int32_t
ctgdGetRentNum
(
SCtgRentMgmt
*
rent
)
{
...
@@ -363,17 +363,17 @@ void ctgdShowDBCache(SCatalog* pCtg, SHashObj *dbHash) {
...
@@ -363,17 +363,17 @@ void ctgdShowDBCache(SCatalog* pCtg, SHashObj *dbHash) {
dbFName
=
taosHashGetKey
(
pIter
,
&
len
);
dbFName
=
taosHashGetKey
(
pIter
,
&
len
);
int32_t
metaNum
=
dbCache
->
tbCache
.
metaCache
?
taosHashGetSize
(
dbCache
->
tbCache
.
meta
Cache
)
:
0
;
int32_t
metaNum
=
dbCache
->
tbCache
?
taosHashGetSize
(
dbCache
->
tb
Cache
)
:
0
;
int32_t
stbNum
=
dbCache
->
tbCache
.
stbCache
?
taosHashGetSize
(
dbCache
->
tbCache
.
stbCache
)
:
0
;
int32_t
stbNum
=
dbCache
->
stbCache
?
taosHashGetSize
(
dbCache
->
stbCache
)
:
0
;
int32_t
vgVersion
=
CTG_DEFAULT_INVALID_VERSION
;
int32_t
vgVersion
=
CTG_DEFAULT_INVALID_VERSION
;
int32_t
hashMethod
=
-
1
;
int32_t
hashMethod
=
-
1
;
int32_t
vgNum
=
0
;
int32_t
vgNum
=
0
;
if
(
dbCache
->
vgInfo
)
{
if
(
dbCache
->
vg
Cache
.
vg
Info
)
{
vgVersion
=
dbCache
->
vgInfo
->
vgVersion
;
vgVersion
=
dbCache
->
vg
Cache
.
vg
Info
->
vgVersion
;
hashMethod
=
dbCache
->
vgInfo
->
hashMethod
;
hashMethod
=
dbCache
->
vg
Cache
.
vg
Info
->
hashMethod
;
if
(
dbCache
->
vgInfo
->
vgHash
)
{
if
(
dbCache
->
vg
Cache
.
vg
Info
->
vgHash
)
{
vgNum
=
taosHashGetSize
(
dbCache
->
vgInfo
->
vgHash
);
vgNum
=
taosHashGetSize
(
dbCache
->
vg
Cache
.
vg
Info
->
vgHash
);
}
}
}
}
...
...
source/libs/catalog/src/ctgRemote.c
浏览文件 @
2861534a
...
@@ -431,7 +431,7 @@ int32_t ctgGetIndexInfoFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const
...
@@ -431,7 +431,7 @@ int32_t ctgGetIndexInfoFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
ctgGetTbIndexFromMnode
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
SName
*
name
,
S
Array
*
*
out
,
SCtgTask
*
pTask
)
{
int32_t
ctgGetTbIndexFromMnode
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
SName
*
name
,
S
TableIndex
*
out
,
SCtgTask
*
pTask
)
{
char
*
msg
=
NULL
;
char
*
msg
=
NULL
;
int32_t
msgLen
=
0
;
int32_t
msgLen
=
0
;
int32_t
reqType
=
TDMT_MND_GET_TABLE_INDEX
;
int32_t
reqType
=
TDMT_MND_GET_TABLE_INDEX
;
...
@@ -448,10 +448,11 @@ int32_t ctgGetTbIndexFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SName *n
...
@@ -448,10 +448,11 @@ int32_t ctgGetTbIndexFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SName *n
}
}
if
(
pTask
)
{
if
(
pTask
)
{
void
*
pOut
=
taosMemoryCalloc
(
1
,
POINTER_BYTES
);
void
*
pOut
=
taosMemoryCalloc
(
1
,
sizeof
(
STableIndex
)
);
if
(
NULL
==
pOut
)
{
if
(
NULL
==
pOut
)
{
CTG_ERR_RET
(
TSDB_CODE_OUT_OF_MEMORY
);
CTG_ERR_RET
(
TSDB_CODE_OUT_OF_MEMORY
);
}
}
CTG_ERR_RET
(
ctgUpdateMsgCtx
(
&
pTask
->
msgCtx
,
reqType
,
pOut
,
(
char
*
)
tbFName
));
CTG_ERR_RET
(
ctgUpdateMsgCtx
(
&
pTask
->
msgCtx
,
reqType
,
pOut
,
(
char
*
)
tbFName
));
CTG_RET
(
ctgAsyncSendMsg
(
pCtg
,
pConn
,
pTask
,
reqType
,
msg
,
msgLen
));
CTG_RET
(
ctgAsyncSendMsg
(
pCtg
,
pConn
,
pTask
,
reqType
,
msg
,
msgLen
));
...
...
source/libs/catalog/src/ctgUtil.c
浏览文件 @
2861534a
...
@@ -44,6 +44,16 @@ char *ctgTaskTypeStr(CTG_TASK_TYPE type) {
...
@@ -44,6 +44,16 @@ char *ctgTaskTypeStr(CTG_TASK_TYPE type) {
}
}
}
}
void
ctgFreeSTableIndex
(
void
*
info
)
{
if
(
NULL
==
info
)
{
return
;
}
STableIndex
*
pInfo
=
(
STableIndex
*
)
info
;
taosArrayDestroyEx
(
pInfo
->
pIndex
,
tFreeSTableIndexInfo
);
}
void
ctgFreeSMetaData
(
SMetaData
*
pData
)
{
void
ctgFreeSMetaData
(
SMetaData
*
pData
)
{
taosArrayDestroy
(
pData
->
pTableMeta
);
taosArrayDestroy
(
pData
->
pTableMeta
);
pData
->
pTableMeta
=
NULL
;
pData
->
pTableMeta
=
NULL
;
...
@@ -110,25 +120,39 @@ void ctgFreeMetaRent(SCtgRentMgmt *mgmt) {
...
@@ -110,25 +120,39 @@ void ctgFreeMetaRent(SCtgRentMgmt *mgmt) {
taosMemoryFreeClear
(
mgmt
->
slots
);
taosMemoryFreeClear
(
mgmt
->
slots
);
}
}
void
ctgFreeStbMetaCache
(
SCtgDBCache
*
dbCache
)
{
if
(
NULL
==
dbCache
->
stbCache
)
{
return
;
}
void
ctgFreeTbMetaCache
(
SCtgTbMetaCache
*
cache
)
{
int32_t
stblNum
=
taosHashGetSize
(
dbCache
->
stbCache
);
CTG_LOCK
(
CTG_WRITE
,
&
cache
->
stbLock
);
taosHashCleanup
(
dbCache
->
stbCache
);
if
(
cache
->
stbCache
)
{
dbCache
->
stbCache
=
NULL
;
int32_t
stblNum
=
taosHashGetSize
(
cache
->
stbCache
);
taosHashCleanup
(
cache
->
stbCache
);
cache
->
stbCache
=
NULL
;
CTG_CACHE_STAT_DEC
(
stblNum
,
stblNum
);
CTG_CACHE_STAT_DEC
(
stblNum
,
stblNum
);
}
void
ctgFreeTbCacheImpl
(
SCtgTbCache
*
pCache
)
{
taosMemoryFreeClear
(
pCache
->
pMeta
);
if
(
pCache
->
pIndex
)
{
taosArrayDestroyEx
(
pCache
->
pIndex
->
pIndex
,
tFreeSTableIndexInfo
);
taosMemoryFreeClear
(
pCache
->
pIndex
);
}
}
CTG_UNLOCK
(
CTG_WRITE
,
&
cache
->
stbLock
);
}
CTG_LOCK
(
CTG_WRITE
,
&
cache
->
metaLock
);
void
ctgFreeTbCache
(
SCtgDBCache
*
dbCache
)
{
if
(
cache
->
metaCache
)
{
if
(
NULL
==
dbCache
->
tbCache
)
{
int32_t
tblNum
=
taosHashGetSize
(
cache
->
metaCache
);
return
;
taosHashCleanup
(
cache
->
metaCache
);
}
cache
->
metaCache
=
NULL
;
CTG_CACHE_STAT_DEC
(
tblNum
,
tblNum
);
int32_t
tblNum
=
taosHashGetSize
(
dbCache
->
tbCache
);
SCtgTbCache
*
pCache
=
taosHashIterate
(
dbCache
->
tbCache
,
NULL
);
while
(
NULL
!=
pCache
)
{
ctgFreeTbCacheImpl
(
pCache
);
pCache
=
taosHashIterate
(
dbCache
->
tbCache
,
pCache
);
}
}
CTG_UNLOCK
(
CTG_WRITE
,
&
cache
->
metaLock
);
taosHashCleanup
(
dbCache
->
tbCache
);
dbCache
->
tbCache
=
NULL
;
CTG_CACHE_STAT_DEC
(
tblNum
,
tblNum
);
}
}
void
ctgFreeVgInfo
(
SDBVgInfo
*
vgInfo
)
{
void
ctgFreeVgInfo
(
SDBVgInfo
*
vgInfo
)
{
...
@@ -144,16 +168,18 @@ void ctgFreeVgInfo(SDBVgInfo *vgInfo) {
...
@@ -144,16 +168,18 @@ void ctgFreeVgInfo(SDBVgInfo *vgInfo) {
taosMemoryFreeClear
(
vgInfo
);
taosMemoryFreeClear
(
vgInfo
);
}
}
void
ctgFreeVgInfoCache
(
SCtgDBCache
*
dbCache
)
{
ctgFreeVgInfo
(
dbCache
->
vgCache
.
vgInfo
);
}
void
ctgFreeDbCache
(
SCtgDBCache
*
dbCache
)
{
void
ctgFreeDbCache
(
SCtgDBCache
*
dbCache
)
{
if
(
NULL
==
dbCache
)
{
if
(
NULL
==
dbCache
)
{
return
;
return
;
}
}
CTG_LOCK
(
CTG_WRITE
,
&
dbCache
->
vgLock
);
ctgFreeVgInfoCache
(
dbCache
);
ctgFreeVgInfo
(
dbCache
->
vgInfo
);
ctgFreeStbMetaCache
(
dbCache
);
CTG_UNLOCK
(
CTG_WRITE
,
&
dbCache
->
vgLock
);
ctgFreeTbCache
(
dbCache
);
ctgFreeTbMetaCache
(
&
dbCache
->
tbCache
);
}
}
...
@@ -167,16 +193,13 @@ void ctgFreeHandle(SCatalog* pCtg) {
...
@@ -167,16 +193,13 @@ void ctgFreeHandle(SCatalog* pCtg) {
void
*
pIter
=
taosHashIterate
(
pCtg
->
dbCache
,
NULL
);
void
*
pIter
=
taosHashIterate
(
pCtg
->
dbCache
,
NULL
);
while
(
pIter
)
{
while
(
pIter
)
{
SCtgDBCache
*
dbCache
=
pIter
;
SCtgDBCache
*
dbCache
=
pIter
;
atomic_store_8
(
&
dbCache
->
deleted
,
1
);
atomic_store_8
(
&
dbCache
->
deleted
,
1
);
ctgFreeDbCache
(
dbCache
);
ctgFreeDbCache
(
dbCache
);
pIter
=
taosHashIterate
(
pCtg
->
dbCache
,
pIter
);
pIter
=
taosHashIterate
(
pCtg
->
dbCache
,
pIter
);
}
}
taosHashCleanup
(
pCtg
->
dbCache
);
taosHashCleanup
(
pCtg
->
dbCache
);
CTG_CACHE_STAT_DEC
(
dbNum
,
dbNum
);
CTG_CACHE_STAT_DEC
(
dbNum
,
dbNum
);
}
}
...
@@ -186,14 +209,12 @@ void ctgFreeHandle(SCatalog* pCtg) {
...
@@ -186,14 +209,12 @@ void ctgFreeHandle(SCatalog* pCtg) {
void
*
pIter
=
taosHashIterate
(
pCtg
->
userCache
,
NULL
);
void
*
pIter
=
taosHashIterate
(
pCtg
->
userCache
,
NULL
);
while
(
pIter
)
{
while
(
pIter
)
{
SCtgUserAuth
*
userCache
=
pIter
;
SCtgUserAuth
*
userCache
=
pIter
;
ctgFreeSCtgUserAuth
(
userCache
);
ctgFreeSCtgUserAuth
(
userCache
);
pIter
=
taosHashIterate
(
pCtg
->
userCache
,
pIter
);
pIter
=
taosHashIterate
(
pCtg
->
userCache
,
pIter
);
}
}
taosHashCleanup
(
pCtg
->
userCache
);
taosHashCleanup
(
pCtg
->
userCache
);
CTG_CACHE_STAT_DEC
(
userNum
,
userNum
);
CTG_CACHE_STAT_DEC
(
userNum
,
userNum
);
}
}
...
@@ -252,9 +273,9 @@ void ctgFreeMsgCtx(SCtgMsgCtx* pCtx) {
...
@@ -252,9 +273,9 @@ void ctgFreeMsgCtx(SCtgMsgCtx* pCtx) {
break
;
break
;
}
}
case
TDMT_MND_GET_TABLE_INDEX
:
{
case
TDMT_MND_GET_TABLE_INDEX
:
{
S
Array
**
pOut
=
(
SArray
*
*
)
pCtx
->
out
;
S
TableIndex
*
pOut
=
(
STableIndex
*
)
pCtx
->
out
;
if
(
pOut
)
{
if
(
pOut
)
{
taosArrayDestroyEx
(
*
pOut
,
tFreeSTableIndexInfo
);
taosArrayDestroyEx
(
pOut
->
pIndex
,
tFreeSTableIndexInfo
);
taosMemoryFreeClear
(
pCtx
->
out
);
taosMemoryFreeClear
(
pCtx
->
out
);
}
}
break
;
break
;
...
@@ -535,9 +556,9 @@ int32_t ctgGetVgInfoFromHashValue(SCatalog *pCtg, SDBVgInfo *dbInfo, const SName
...
@@ -535,9 +556,9 @@ int32_t ctgGetVgInfoFromHashValue(SCatalog *pCtg, SDBVgInfo *dbInfo, const SName
}
}
int32_t
ctgStbVersionSearchCompare
(
const
void
*
key1
,
const
void
*
key2
)
{
int32_t
ctgStbVersionSearchCompare
(
const
void
*
key1
,
const
void
*
key2
)
{
if
(
*
(
uint64_t
*
)
key1
<
((
SSTable
Meta
Version
*
)
key2
)
->
suid
)
{
if
(
*
(
uint64_t
*
)
key1
<
((
SSTableVersion
*
)
key2
)
->
suid
)
{
return
-
1
;
return
-
1
;
}
else
if
(
*
(
uint64_t
*
)
key1
>
((
SSTable
Meta
Version
*
)
key2
)
->
suid
)
{
}
else
if
(
*
(
uint64_t
*
)
key1
>
((
SSTableVersion
*
)
key2
)
->
suid
)
{
return
1
;
return
1
;
}
else
{
}
else
{
return
0
;
return
0
;
...
@@ -555,9 +576,9 @@ int32_t ctgDbVgVersionSearchCompare(const void* key1, const void* key2) {
...
@@ -555,9 +576,9 @@ int32_t ctgDbVgVersionSearchCompare(const void* key1, const void* key2) {
}
}
int32_t
ctgStbVersionSortCompare
(
const
void
*
key1
,
const
void
*
key2
)
{
int32_t
ctgStbVersionSortCompare
(
const
void
*
key1
,
const
void
*
key2
)
{
if
(((
SSTable
MetaVersion
*
)
key1
)
->
suid
<
((
SSTableMeta
Version
*
)
key2
)
->
suid
)
{
if
(((
SSTable
Version
*
)
key1
)
->
suid
<
((
SSTable
Version
*
)
key2
)
->
suid
)
{
return
-
1
;
return
-
1
;
}
else
if
(((
SSTable
MetaVersion
*
)
key1
)
->
suid
>
((
SSTableMeta
Version
*
)
key2
)
->
suid
)
{
}
else
if
(((
SSTable
Version
*
)
key1
)
->
suid
>
((
SSTable
Version
*
)
key2
)
->
suid
)
{
return
1
;
return
1
;
}
else
{
}
else
{
return
0
;
return
0
;
...
@@ -640,6 +661,27 @@ int32_t ctgCloneMetaOutput(STableMetaOutput *output, STableMetaOutput **pOutput)
...
@@ -640,6 +661,27 @@ int32_t ctgCloneMetaOutput(STableMetaOutput *output, STableMetaOutput **pOutput)
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
ctgCloneTableIndex
(
SArray
*
pIndex
,
SArray
**
pRes
)
{
if
(
NULL
==
pIndex
)
{
*
pRes
=
NULL
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
num
=
taosArrayGetSize
(
pIndex
);
*
pRes
=
taosArrayInit
(
num
,
sizeof
(
STableIndexInfo
));
if
(
NULL
==
*
pRes
)
{
CTG_ERR_RET
(
TSDB_CODE_OUT_OF_MEMORY
);
}
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
STableIndexInfo
*
pInfo
=
taosArrayGet
(
pIndex
,
i
);
taosArrayPush
(
*
pRes
,
pInfo
);
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
ctgUpdateSendTargetInfo
(
SMsgSendInfo
*
pMsgSendInfo
,
int32_t
msgType
,
SCtgTask
*
pTask
)
{
int32_t
ctgUpdateSendTargetInfo
(
SMsgSendInfo
*
pMsgSendInfo
,
int32_t
msgType
,
SCtgTask
*
pTask
)
{
if
(
msgType
==
TDMT_VND_TABLE_META
)
{
if
(
msgType
==
TDMT_VND_TABLE_META
)
{
SCtgTbMetaCtx
*
ctx
=
(
SCtgTbMetaCtx
*
)
pTask
->
taskCtx
;
SCtgTbMetaCtx
*
ctx
=
(
SCtgTbMetaCtx
*
)
pTask
->
taskCtx
;
...
...
source/libs/catalog/test/catalogTests.cpp
浏览文件 @
2861534a
...
@@ -895,9 +895,9 @@ void *ctgTestSetCtableMetaThread(void *param) {
...
@@ -895,9 +895,9 @@ void *ctgTestSetCtableMetaThread(void *param) {
output
=
(
STableMetaOutput
*
)
taosMemoryMalloc
(
sizeof
(
STableMetaOutput
));
output
=
(
STableMetaOutput
*
)
taosMemoryMalloc
(
sizeof
(
STableMetaOutput
));
ctgTestBuildCTableMetaOutput
(
output
);
ctgTestBuildCTableMetaOutput
(
output
);
SCtgUpdateTb
lMsg
*
msg
=
(
SCtgUpdateTblMsg
*
)
taosMemoryMalloc
(
sizeof
(
SCtgUpdateTbl
Msg
));
SCtgUpdateTb
MetaMsg
*
msg
=
(
SCtgUpdateTbMetaMsg
*
)
taosMemoryMalloc
(
sizeof
(
SCtgUpdateTbMeta
Msg
));
msg
->
pCtg
=
pCtg
;
msg
->
pCtg
=
pCtg
;
msg
->
output
=
output
;
msg
->
pMeta
=
output
;
operation
.
data
=
msg
;
operation
.
data
=
msg
;
code
=
ctgOpUpdateTbMeta
(
&
operation
);
code
=
ctgOpUpdateTbMeta
(
&
operation
);
...
@@ -989,7 +989,7 @@ TEST(tableMeta, normalTable) {
...
@@ -989,7 +989,7 @@ TEST(tableMeta, normalTable) {
ASSERT_EQ
(
tableMeta
->
tableInfo
.
rowSize
,
12
);
ASSERT_EQ
(
tableMeta
->
tableInfo
.
rowSize
,
12
);
SDbVgVersion
*
dbs
=
NULL
;
SDbVgVersion
*
dbs
=
NULL
;
SSTable
Meta
Version
*
stb
=
NULL
;
SSTableVersion
*
stb
=
NULL
;
uint32_t
dbNum
=
0
,
stbNum
=
0
,
allDbNum
=
0
,
allStbNum
=
0
;
uint32_t
dbNum
=
0
,
stbNum
=
0
,
allDbNum
=
0
,
allStbNum
=
0
;
int32_t
i
=
0
;
int32_t
i
=
0
;
while
(
i
<
5
)
{
while
(
i
<
5
)
{
...
@@ -1098,7 +1098,7 @@ TEST(tableMeta, childTableCase) {
...
@@ -1098,7 +1098,7 @@ TEST(tableMeta, childTableCase) {
ASSERT_EQ
(
tableMeta
->
tableInfo
.
rowSize
,
12
);
ASSERT_EQ
(
tableMeta
->
tableInfo
.
rowSize
,
12
);
SDbVgVersion
*
dbs
=
NULL
;
SDbVgVersion
*
dbs
=
NULL
;
SSTable
Meta
Version
*
stb
=
NULL
;
SSTableVersion
*
stb
=
NULL
;
uint32_t
dbNum
=
0
,
stbNum
=
0
,
allDbNum
=
0
,
allStbNum
=
0
;
uint32_t
dbNum
=
0
,
stbNum
=
0
,
allDbNum
=
0
,
allStbNum
=
0
;
int32_t
i
=
0
;
int32_t
i
=
0
;
while
(
i
<
5
)
{
while
(
i
<
5
)
{
...
@@ -1220,7 +1220,7 @@ TEST(tableMeta, superTableCase) {
...
@@ -1220,7 +1220,7 @@ TEST(tableMeta, superTableCase) {
ASSERT_EQ
(
tableMeta
->
tableInfo
.
rowSize
,
12
);
ASSERT_EQ
(
tableMeta
->
tableInfo
.
rowSize
,
12
);
SDbVgVersion
*
dbs
=
NULL
;
SDbVgVersion
*
dbs
=
NULL
;
SSTable
Meta
Version
*
stb
=
NULL
;
SSTableVersion
*
stb
=
NULL
;
uint32_t
dbNum
=
0
,
stbNum
=
0
,
allDbNum
=
0
,
allStbNum
=
0
;
uint32_t
dbNum
=
0
,
stbNum
=
0
,
allDbNum
=
0
,
allStbNum
=
0
;
int32_t
i
=
0
;
int32_t
i
=
0
;
while
(
i
<
5
)
{
while
(
i
<
5
)
{
...
@@ -2299,7 +2299,7 @@ TEST(rentTest, allRent) {
...
@@ -2299,7 +2299,7 @@ TEST(rentTest, allRent) {
SArray
*
vgList
=
NULL
;
SArray
*
vgList
=
NULL
;
ctgTestStop
=
false
;
ctgTestStop
=
false
;
SDbVgVersion
*
dbs
=
NULL
;
SDbVgVersion
*
dbs
=
NULL
;
SSTable
Meta
Version
*
stable
=
NULL
;
SSTableVersion
*
stable
=
NULL
;
uint32_t
num
=
0
;
uint32_t
num
=
0
;
ctgTestInitLogFile
();
ctgTestInitLogFile
();
...
...
source/libs/qcom/src/querymsg.c
浏览文件 @
2861534a
...
@@ -484,14 +484,12 @@ int32_t queryProcessGetTbIndexRsp(void *output, char *msg, int32_t msgSize) {
...
@@ -484,14 +484,12 @@ int32_t queryProcessGetTbIndexRsp(void *output, char *msg, int32_t msgSize) {
return
TSDB_CODE_TSC_INVALID_INPUT
;
return
TSDB_CODE_TSC_INVALID_INPUT
;
}
}
STableIndexRsp
out
=
{
0
}
;
STableIndexRsp
*
out
=
(
STableIndexRsp
*
)
output
;
if
(
tDeserializeSTableIndexRsp
(
msg
,
msgSize
,
&
out
)
!=
0
)
{
if
(
tDeserializeSTableIndexRsp
(
msg
,
msgSize
,
out
)
!=
0
)
{
qError
(
"tDeserializeSTableIndexRsp failed, msgSize:%d"
,
msgSize
);
qError
(
"tDeserializeSTableIndexRsp failed, msgSize:%d"
,
msgSize
);
return
TSDB_CODE_INVALID_MSG
;
return
TSDB_CODE_INVALID_MSG
;
}
}
*
(
void
**
)
output
=
out
.
pIndex
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
...
source/libs/qworker/src/qworker.c
浏览文件 @
2861534a
...
@@ -837,7 +837,6 @@ void qwProcessHbTimerEvent(void *param, void *tmrId) {
...
@@ -837,7 +837,6 @@ void qwProcessHbTimerEvent(void *param, void *tmrId) {
SQWorker
*
mgmt
=
qwAcquire
(
refId
);
SQWorker
*
mgmt
=
qwAcquire
(
refId
);
if
(
NULL
==
mgmt
)
{
if
(
NULL
==
mgmt
)
{
QW_DLOG
(
"qwAcquire %"
PRIx64
"failed"
,
refId
);
QW_DLOG
(
"qwAcquire %"
PRIx64
"failed"
,
refId
);
taosMemoryFree
(
param
);
return
;
return
;
}
}
...
...
source/libs/scalar/src/filter.c
浏览文件 @
2861534a
...
@@ -1476,6 +1476,11 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
...
@@ -1476,6 +1476,11 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
for
(
uint32_t
i
=
0
;
i
<
info
->
fields
[
FLD_TYPE_VALUE
].
num
;
++
i
)
{
for
(
uint32_t
i
=
0
;
i
<
info
->
fields
[
FLD_TYPE_VALUE
].
num
;
++
i
)
{
SFilterField
*
field
=
&
info
->
fields
[
FLD_TYPE_VALUE
].
fields
[
i
];
SFilterField
*
field
=
&
info
->
fields
[
FLD_TYPE_VALUE
].
fields
[
i
];
if
(
field
->
desc
)
{
if
(
field
->
desc
)
{
if
(
QUERY_NODE_VALUE
!=
nodeType
(
field
->
desc
))
{
qDebug
(
"VAL%d => [type:not value node][val:NIL]"
,
i
);
//TODO
continue
;
}
SValueNode
*
var
=
(
SValueNode
*
)
field
->
desc
;
SValueNode
*
var
=
(
SValueNode
*
)
field
->
desc
;
SDataType
*
dType
=
&
var
->
node
.
resType
;
SDataType
*
dType
=
&
var
->
node
.
resType
;
if
(
dType
->
type
==
TSDB_DATA_TYPE_VALUE_ARRAY
)
{
if
(
dType
->
type
==
TSDB_DATA_TYPE_VALUE_ARRAY
)
{
...
...
source/util/src/tarray.c
浏览文件 @
2861534a
...
@@ -458,6 +458,9 @@ static void taosArrayInsertSort(SArray* pArray, __ext_compar_fn_t fn, const void
...
@@ -458,6 +458,9 @@ static void taosArrayInsertSort(SArray* pArray, __ext_compar_fn_t fn, const void
}
}
SArray
*
taosArrayDeepCopy
(
const
SArray
*
pSrc
,
FCopy
deepCopy
)
{
SArray
*
taosArrayDeepCopy
(
const
SArray
*
pSrc
,
FCopy
deepCopy
)
{
if
(
NULL
==
pSrc
)
{
return
NULL
;
}
ASSERT
(
pSrc
->
elemSize
==
sizeof
(
void
*
));
ASSERT
(
pSrc
->
elemSize
==
sizeof
(
void
*
));
SArray
*
pArray
=
taosArrayInit
(
pSrc
->
size
,
sizeof
(
void
*
));
SArray
*
pArray
=
taosArrayInit
(
pSrc
->
size
,
sizeof
(
void
*
));
for
(
int32_t
i
=
0
;
i
<
pSrc
->
size
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
pSrc
->
size
;
i
++
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录