Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
768beb64
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
768beb64
编写于
5月 28, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: parser adapts asynchronous interface
上级
c863c61d
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
183 addition
and
92 deletion
+183
-92
source/libs/parser/inc/parUtil.h
source/libs/parser/inc/parUtil.h
+8
-1
source/libs/parser/src/parAstParser.c
source/libs/parser/src/parAstParser.c
+10
-0
source/libs/parser/src/parAuthenticator.c
source/libs/parser/src/parAuthenticator.c
+17
-89
source/libs/parser/src/parUtil.c
source/libs/parser/src/parUtil.c
+98
-1
source/libs/parser/test/mockCatalogService.cpp
source/libs/parser/test/mockCatalogService.cpp
+32
-0
source/libs/parser/test/parInitialDTest.cpp
source/libs/parser/test/parInitialDTest.cpp
+1
-0
source/libs/parser/test/parTestUtil.cpp
source/libs/parser/test/parTestUtil.cpp
+16
-1
source/libs/parser/test/parTestUtil.h
source/libs/parser/test/parTestUtil.h
+1
-0
未找到文件。
source/libs/parser/inc/parUtil.h
浏览文件 @
768beb64
...
...
@@ -42,7 +42,9 @@ typedef struct SParseMetaCache {
SHashObj
*
pTableMeta
;
// key is tbFName, element is STableMeta*
SHashObj
*
pDbVgroup
;
// key is dbFName, element is SArray<SVgroupInfo>*
SHashObj
*
pTableVgroup
;
// key is tbFName, element is SVgroupInfo*
SHashObj
*
pDbCfg
;
// key is tbFName, element is SDbCfgInfo
SHashObj
*
pDbCfg
;
// key is tbFName, element is SDbCfgInfo*
SHashObj
*
pDbInfo
;
// key is tbFName, element is SDbInfo*
SHashObj
*
pUserAuth
;
// key is SUserAuthInfo serialized string, element is bool indicating whether or not to pass
}
SParseMetaCache
;
int32_t
generateSyntaxErrMsg
(
SMsgBuf
*
pBuf
,
int32_t
errCode
,
...);
...
...
@@ -64,13 +66,18 @@ int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMet
int32_t
reserveTableMetaInCache
(
int32_t
acctId
,
const
char
*
pDb
,
const
char
*
pTable
,
SParseMetaCache
*
pMetaCache
);
int32_t
reserveDbVgInfoInCache
(
int32_t
acctId
,
const
char
*
pDb
,
SParseMetaCache
*
pMetaCache
);
int32_t
reserveTableVgroupInCache
(
int32_t
acctId
,
const
char
*
pDb
,
const
char
*
pTable
,
SParseMetaCache
*
pMetaCache
);
int32_t
reserveDbVgVersionInCache
(
int32_t
acctId
,
const
char
*
pDb
,
SParseMetaCache
*
pMetaCache
);
int32_t
reserveDbCfgInCache
(
int32_t
acctId
,
const
char
*
pDb
,
SParseMetaCache
*
pMetaCache
);
int32_t
reserveUserAuthInCache
(
int32_t
acctId
,
const
char
*
pUser
,
const
char
*
pDb
,
AUTH_TYPE
type
,
SParseMetaCache
*
pMetaCache
);
int32_t
getTableMetaFromCache
(
SParseMetaCache
*
pMetaCache
,
const
SName
*
pName
,
STableMeta
**
pMeta
);
int32_t
getDbVgInfoFromCache
(
SParseMetaCache
*
pMetaCache
,
const
char
*
pDbFName
,
SArray
**
pVgInfo
);
int32_t
getTableVgroupFromCache
(
SParseMetaCache
*
pMetaCache
,
const
SName
*
pName
,
SVgroupInfo
*
pVgroup
);
int32_t
getDbVgVersionFromCache
(
SParseMetaCache
*
pMetaCache
,
const
char
*
pDbFName
,
int32_t
*
pVersion
,
int64_t
*
pDbId
,
int32_t
*
pTableNum
);
int32_t
getDbCfgFromCache
(
SParseMetaCache
*
pMetaCache
,
const
char
*
pDbFName
,
SDbCfgInfo
*
pInfo
);
int32_t
getUserAuthFromCache
(
SParseMetaCache
*
pMetaCache
,
const
char
*
pUser
,
const
char
*
pDb
,
AUTH_TYPE
type
,
bool
*
pPass
);
#ifdef __cplusplus
}
...
...
source/libs/parser/src/parAstParser.c
浏览文件 @
768beb64
...
...
@@ -112,6 +112,10 @@ static EDealRes collectMetaKeyFromRealTable(SCollectMetaKeyFromExprCxt* pCxt, SR
pCxt
->
errCode
=
reserveTableVgroupInCache
(
pCxt
->
pComCxt
->
pParseCxt
->
acctId
,
pRealTable
->
table
.
dbName
,
pRealTable
->
table
.
tableName
,
pCxt
->
pComCxt
->
pMetaCache
);
}
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
)
{
pCxt
->
errCode
=
reserveUserAuthInCache
(
pCxt
->
pComCxt
->
pParseCxt
->
acctId
,
pCxt
->
pComCxt
->
pParseCxt
->
pUser
,
pRealTable
->
table
.
dbName
,
AUTH_TYPE_READ
,
pCxt
->
pComCxt
->
pMetaCache
);
}
return
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
?
DEAL_RES_CONTINUE
:
DEAL_RES_ERROR
;
}
...
...
@@ -191,6 +195,10 @@ static int32_t collectMetaKeyFromAlterTable(SCollectMetaKeyCxt* pCxt, SAlterTabl
return
code
;
}
static
int32_t
collectMetaKeyFromUseDatabase
(
SCollectMetaKeyCxt
*
pCxt
,
SUseDatabaseStmt
*
pStmt
)
{
return
reserveDbVgVersionInCache
(
pCxt
->
pParseCxt
->
acctId
,
pStmt
->
dbName
,
pCxt
->
pMetaCache
);
}
static
int32_t
collectMetaKeyFromCreateIndex
(
SCollectMetaKeyCxt
*
pCxt
,
SCreateIndexStmt
*
pStmt
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
INDEX_TYPE_SMA
==
pStmt
->
indexType
)
{
...
...
@@ -337,7 +345,9 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
case
QUERY_NODE_CREATE_USER_STMT
:
case
QUERY_NODE_ALTER_USER_STMT
:
case
QUERY_NODE_DROP_USER_STMT
:
break
;
case
QUERY_NODE_USE_DATABASE_STMT
:
return
collectMetaKeyFromUseDatabase
(
pCxt
,
(
SUseDatabaseStmt
*
)
pStmt
);
case
QUERY_NODE_CREATE_DNODE_STMT
:
case
QUERY_NODE_DROP_DNODE_STMT
:
case
QUERY_NODE_ALTER_DNODE_STMT
:
...
...
source/libs/parser/src/parAuthenticator.c
浏览文件 @
768beb64
...
...
@@ -18,23 +18,30 @@
#include "parInt.h"
typedef
struct
SAuthCxt
{
SParseContext
*
pParseCxt
;
int32_t
errCode
;
SParseContext
*
pParseCxt
;
SParseMetaCache
*
pMetaCache
;
int32_t
errCode
;
}
SAuthCxt
;
static
int32_t
authQuery
(
SAuthCxt
*
pCxt
,
SNode
*
pStmt
);
static
int32_t
checkAuth
(
SParseContext
*
pCxt
,
const
char
*
pDbName
,
AUTH_TYPE
type
)
{
if
(
pCxt
->
isSuperUser
)
{
static
int32_t
checkAuth
(
SAuthCxt
*
pCxt
,
const
char
*
pDbName
,
AUTH_TYPE
type
)
{
SParseContext
*
pParseCxt
=
pCxt
->
pParseCxt
;
if
(
pParseCxt
->
isSuperUser
)
{
return
TSDB_CODE_SUCCESS
;
}
SName
name
;
tNameSetDbName
(
&
name
,
pCxt
->
acctId
,
pDbName
,
strlen
(
pDbName
));
tNameSetDbName
(
&
name
,
p
Parse
Cxt
->
acctId
,
pDbName
,
strlen
(
pDbName
));
char
dbFname
[
TSDB_DB_FNAME_LEN
]
=
{
0
};
tNameGetFullDbName
(
&
name
,
dbFname
);
int32_t
code
=
TSDB_CODE_SUCCESS
;
bool
pass
=
false
;
int32_t
code
=
catalogChkAuth
(
pCxt
->
pCatalog
,
pCxt
->
pTransporter
,
&
pCxt
->
mgmtEpSet
,
pCxt
->
pUser
,
dbFname
,
type
,
&
pass
);
if
(
NULL
!=
pCxt
->
pMetaCache
)
{
code
=
getUserAuthFromCache
(
pCxt
->
pMetaCache
,
pParseCxt
->
pUser
,
dbFname
,
type
,
&
pass
);
}
else
{
code
=
catalogChkAuth
(
pParseCxt
->
pCatalog
,
pParseCxt
->
pTransporter
,
&
pParseCxt
->
mgmtEpSet
,
pParseCxt
->
pUser
,
dbFname
,
type
,
&
pass
);
}
return
TSDB_CODE_SUCCESS
==
code
?
(
pass
?
TSDB_CODE_SUCCESS
:
TSDB_CODE_PAR_PERMISSION_DENIED
)
:
code
;
}
...
...
@@ -45,7 +52,7 @@ static EDealRes authSubquery(SAuthCxt* pCxt, SNode* pStmt) {
static
EDealRes
authSelectImpl
(
SNode
*
pNode
,
void
*
pContext
)
{
SAuthCxt
*
pCxt
=
pContext
;
if
(
QUERY_NODE_REAL_TABLE
==
nodeType
(
pNode
))
{
pCxt
->
errCode
=
checkAuth
(
pCxt
->
pParseCxt
,
((
SRealTableNode
*
)
pNode
)
->
table
.
dbName
,
AUTH_TYPE_READ
);
pCxt
->
errCode
=
checkAuth
(
pCxt
,
((
SRealTableNode
*
)
pNode
)
->
table
.
dbName
,
AUTH_TYPE_READ
);
return
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
?
DEAL_RES_CONTINUE
:
DEAL_RES_ERROR
;
}
else
if
(
QUERY_NODE_TEMP_TABLE
==
nodeType
(
pNode
))
{
return
authSubquery
(
pCxt
,
((
STempTableNode
*
)
pNode
)
->
pSubquery
);
...
...
@@ -79,87 +86,8 @@ static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt) {
return
authSetOperator
(
pCxt
,
(
SSetOperator
*
)
pStmt
);
case
QUERY_NODE_SELECT_STMT
:
return
authSelect
(
pCxt
,
(
SSelectStmt
*
)
pStmt
);
case
QUERY_NODE_CREATE_DATABASE_STMT
:
case
QUERY_NODE_DROP_DATABASE_STMT
:
case
QUERY_NODE_ALTER_DATABASE_STMT
:
case
QUERY_NODE_CREATE_TABLE_STMT
:
case
QUERY_NODE_CREATE_SUBTABLE_CLAUSE
:
case
QUERY_NODE_CREATE_MULTI_TABLE_STMT
:
case
QUERY_NODE_DROP_TABLE_CLAUSE
:
case
QUERY_NODE_DROP_TABLE_STMT
:
case
QUERY_NODE_DROP_SUPER_TABLE_STMT
:
case
QUERY_NODE_ALTER_TABLE_STMT
:
case
QUERY_NODE_CREATE_USER_STMT
:
case
QUERY_NODE_ALTER_USER_STMT
:
break
;
case
QUERY_NODE_DROP_USER_STMT
:
{
case
QUERY_NODE_DROP_USER_STMT
:
return
authDropUser
(
pCxt
,
(
SDropUserStmt
*
)
pStmt
);
}
case
QUERY_NODE_USE_DATABASE_STMT
:
case
QUERY_NODE_CREATE_DNODE_STMT
:
case
QUERY_NODE_DROP_DNODE_STMT
:
case
QUERY_NODE_ALTER_DNODE_STMT
:
case
QUERY_NODE_CREATE_INDEX_STMT
:
case
QUERY_NODE_DROP_INDEX_STMT
:
case
QUERY_NODE_CREATE_QNODE_STMT
:
case
QUERY_NODE_DROP_QNODE_STMT
:
case
QUERY_NODE_CREATE_BNODE_STMT
:
case
QUERY_NODE_DROP_BNODE_STMT
:
case
QUERY_NODE_CREATE_SNODE_STMT
:
case
QUERY_NODE_DROP_SNODE_STMT
:
case
QUERY_NODE_CREATE_MNODE_STMT
:
case
QUERY_NODE_DROP_MNODE_STMT
:
case
QUERY_NODE_CREATE_TOPIC_STMT
:
case
QUERY_NODE_DROP_TOPIC_STMT
:
case
QUERY_NODE_ALTER_LOCAL_STMT
:
case
QUERY_NODE_EXPLAIN_STMT
:
case
QUERY_NODE_DESCRIBE_STMT
:
case
QUERY_NODE_RESET_QUERY_CACHE_STMT
:
case
QUERY_NODE_COMPACT_STMT
:
case
QUERY_NODE_CREATE_FUNCTION_STMT
:
case
QUERY_NODE_DROP_FUNCTION_STMT
:
case
QUERY_NODE_CREATE_STREAM_STMT
:
case
QUERY_NODE_DROP_STREAM_STMT
:
case
QUERY_NODE_MERGE_VGROUP_STMT
:
case
QUERY_NODE_REDISTRIBUTE_VGROUP_STMT
:
case
QUERY_NODE_SPLIT_VGROUP_STMT
:
case
QUERY_NODE_SYNCDB_STMT
:
case
QUERY_NODE_GRANT_STMT
:
case
QUERY_NODE_REVOKE_STMT
:
case
QUERY_NODE_SHOW_DNODES_STMT
:
case
QUERY_NODE_SHOW_MNODES_STMT
:
case
QUERY_NODE_SHOW_MODULES_STMT
:
case
QUERY_NODE_SHOW_QNODES_STMT
:
case
QUERY_NODE_SHOW_SNODES_STMT
:
case
QUERY_NODE_SHOW_BNODES_STMT
:
case
QUERY_NODE_SHOW_CLUSTER_STMT
:
case
QUERY_NODE_SHOW_DATABASES_STMT
:
case
QUERY_NODE_SHOW_FUNCTIONS_STMT
:
case
QUERY_NODE_SHOW_INDEXES_STMT
:
case
QUERY_NODE_SHOW_STABLES_STMT
:
case
QUERY_NODE_SHOW_STREAMS_STMT
:
case
QUERY_NODE_SHOW_TABLES_STMT
:
case
QUERY_NODE_SHOW_USERS_STMT
:
case
QUERY_NODE_SHOW_LICENCE_STMT
:
case
QUERY_NODE_SHOW_VGROUPS_STMT
:
case
QUERY_NODE_SHOW_TOPICS_STMT
:
case
QUERY_NODE_SHOW_CONSUMERS_STMT
:
case
QUERY_NODE_SHOW_SUBSCRIBES_STMT
:
case
QUERY_NODE_SHOW_SMAS_STMT
:
case
QUERY_NODE_SHOW_CONFIGS_STMT
:
case
QUERY_NODE_SHOW_CONNECTIONS_STMT
:
case
QUERY_NODE_SHOW_QUERIES_STMT
:
case
QUERY_NODE_SHOW_VNODES_STMT
:
case
QUERY_NODE_SHOW_APPS_STMT
:
case
QUERY_NODE_SHOW_SCORES_STMT
:
case
QUERY_NODE_SHOW_VARIABLE_STMT
:
case
QUERY_NODE_SHOW_CREATE_DATABASE_STMT
:
case
QUERY_NODE_SHOW_CREATE_TABLE_STMT
:
case
QUERY_NODE_SHOW_CREATE_STABLE_STMT
:
case
QUERY_NODE_SHOW_TRANSACTIONS_STMT
:
case
QUERY_NODE_KILL_CONNECTION_STMT
:
case
QUERY_NODE_KILL_QUERY_STMT
:
case
QUERY_NODE_KILL_TRANSACTION_STMT
:
default:
break
;
}
...
...
@@ -168,6 +96,6 @@ static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt) {
}
int32_t
authenticate
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
)
{
SAuthCxt
cxt
=
{.
pParseCxt
=
pParseCxt
,
.
errCode
=
TSDB_CODE_SUCCESS
};
SAuthCxt
cxt
=
{.
pParseCxt
=
pParseCxt
,
.
pMetaCache
=
pQuery
->
pMetaCache
,
.
errCode
=
TSDB_CODE_SUCCESS
};
return
authQuery
(
&
cxt
,
pQuery
->
pRoot
);
}
source/libs/parser/src/parUtil.c
浏览文件 @
768beb64
...
...
@@ -441,6 +441,28 @@ end:
return
retCode
;
}
#define USER_AUTH_KEY_MAX_LEN TSDB_USER_LEN + TSDB_DB_FNAME_LEN + 2
static
int32_t
userAuthToString
(
int32_t
acctId
,
const
char
*
pUser
,
const
char
*
pDb
,
AUTH_TYPE
type
,
char
*
pStr
)
{
return
sprintf
(
pStr
,
"%s*%d.%s*%d"
,
pUser
,
acctId
,
pDb
,
type
);
}
static
int32_t
userAuthToStringExt
(
const
char
*
pUser
,
const
char
*
pDbFName
,
AUTH_TYPE
type
,
char
*
pStr
)
{
return
sprintf
(
pStr
,
"%s*%s*%d"
,
pUser
,
pDbFName
,
type
);
}
static
void
stringToUserAuth
(
const
char
*
pStr
,
int32_t
len
,
SUserAuthInfo
*
pUserAuth
)
{
char
*
p1
=
strchr
(
pStr
,
'*'
);
strncpy
(
pUserAuth
->
user
,
pStr
,
p1
-
pStr
);
++
p1
;
char
*
p2
=
strchr
(
p1
,
'*'
);
strncpy
(
pUserAuth
->
dbFName
,
p1
,
p2
-
p1
);
++
p2
;
char
buf
[
10
]
=
{
0
};
strncpy
(
buf
,
p2
,
len
-
(
p2
-
pStr
));
pUserAuth
->
type
=
taosStr2Int32
(
buf
,
NULL
,
10
);
}
static
int32_t
buildTableReq
(
SHashObj
*
pTablesHash
,
SArray
**
pTables
)
{
if
(
NULL
!=
pTablesHash
)
{
*
pTables
=
taosArrayInit
(
taosHashGetSize
(
pTablesHash
),
sizeof
(
SName
));
...
...
@@ -495,6 +517,25 @@ static int32_t buildTableVgroupReq(SHashObj* pTableVgroupHash, SArray** pTableVg
static
int32_t
buildDbCfgReq
(
SHashObj
*
pDbCfgHash
,
SArray
**
pDbCfg
)
{
return
buildDbReq
(
pDbCfgHash
,
pDbCfg
);
}
static
int32_t
buildUserAuthReq
(
SHashObj
*
pUserAuthHash
,
SArray
**
pUserAuth
)
{
if
(
NULL
!=
pUserAuthHash
)
{
*
pUserAuth
=
taosArrayInit
(
taosHashGetSize
(
pUserAuthHash
),
sizeof
(
SUserAuthInfo
));
if
(
NULL
==
*
pUserAuth
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
void
*
p
=
taosHashIterate
(
pUserAuthHash
,
NULL
);
while
(
NULL
!=
p
)
{
size_t
len
=
0
;
char
*
pKey
=
taosHashGetKey
(
p
,
&
len
);
SUserAuthInfo
userAuth
=
{
0
};
stringToUserAuth
(
pKey
,
len
,
&
userAuth
);
taosArrayPush
(
*
pUserAuth
,
&
userAuth
);
p
=
taosHashIterate
(
pUserAuthHash
,
p
);
}
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
buildCatalogReq
(
const
SParseMetaCache
*
pMetaCache
,
SCatalogReq
*
pCatalogReq
)
{
int32_t
code
=
buildTableMetaReq
(
pMetaCache
->
pTableMeta
,
&
pCatalogReq
->
pTableMeta
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
@@ -506,6 +547,9 @@ int32_t buildCatalogReq(const SParseMetaCache* pMetaCache, SCatalogReq* pCatalog
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
buildDbCfgReq
(
pMetaCache
->
pDbCfg
,
&
pCatalogReq
->
pDbCfg
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
buildUserAuthReq
(
pMetaCache
->
pUserAuth
,
&
pCatalogReq
->
pUser
);
}
return
code
;
}
...
...
@@ -560,6 +604,19 @@ static int32_t putDbCfgToCache(const SArray* pDbCfgReq, const SArray* pDbCfgData
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
putUserAuthToCache
(
const
SArray
*
pUserAuthReq
,
const
SArray
*
pUserAuthData
,
SHashObj
*
pUserAuth
)
{
int32_t
nvgs
=
taosArrayGetSize
(
pUserAuthReq
);
for
(
int32_t
i
=
0
;
i
<
nvgs
;
++
i
)
{
SUserAuthInfo
*
pUser
=
taosArrayGet
(
pUserAuthReq
,
i
);
char
key
[
USER_AUTH_KEY_MAX_LEN
]
=
{
0
};
int32_t
len
=
userAuthToStringExt
(
pUser
->
user
,
pUser
->
dbFName
,
pUser
->
type
,
key
);
if
(
TSDB_CODE_SUCCESS
!=
taosHashPut
(
pUserAuth
,
key
,
len
,
taosArrayGet
(
pUserAuthData
,
i
),
sizeof
(
bool
)))
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
putMetaDataToCache
(
const
SCatalogReq
*
pCatalogReq
,
const
SMetaData
*
pMetaData
,
SParseMetaCache
*
pMetaCache
)
{
int32_t
code
=
putTableMetaToCache
(
pCatalogReq
->
pTableMeta
,
pMetaData
->
pTableMeta
,
pMetaCache
->
pTableMeta
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
@@ -571,6 +628,9 @@ int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMet
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
putDbCfgToCache
(
pCatalogReq
->
pDbCfg
,
pMetaData
->
pDbCfg
,
pMetaCache
->
pDbCfg
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
putUserAuthToCache
(
pCatalogReq
->
pUser
,
pMetaData
->
pUser
,
pMetaCache
->
pUserAuth
);
}
return
code
;
}
...
...
@@ -650,9 +710,20 @@ int32_t getTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName,
return
TSDB_CODE_SUCCESS
;
}
int32_t
reserveDbVgVersionInCache
(
int32_t
acctId
,
const
char
*
pDb
,
SParseMetaCache
*
pMetaCache
)
{
return
reserveDbReqInCache
(
acctId
,
pDb
,
&
pMetaCache
->
pDbCfg
);
}
int32_t
getDbVgVersionFromCache
(
SParseMetaCache
*
pMetaCache
,
const
char
*
pDbFName
,
int32_t
*
pVersion
,
int64_t
*
pDbId
,
int32_t
*
pTableNum
)
{
return
TSDB_CODE_PAR_INTERNAL_ERROR
;
SDbInfo
**
pRes
=
taosHashGet
(
pMetaCache
->
pDbCfg
,
pDbFName
,
strlen
(
pDbFName
));
if
(
NULL
==
pRes
||
NULL
==
*
pRes
)
{
return
TSDB_CODE_PAR_INTERNAL_ERROR
;
}
*
pVersion
=
(
*
pRes
)
->
vgVer
;
*
pDbId
=
(
*
pRes
)
->
dbId
;
*
pTableNum
=
(
*
pRes
)
->
tbNum
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
reserveDbCfgInCache
(
int32_t
acctId
,
const
char
*
pDb
,
SParseMetaCache
*
pMetaCache
)
{
...
...
@@ -667,3 +738,29 @@ int32_t getDbCfgFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SDb
memcpy
(
pInfo
,
*
pRes
,
sizeof
(
SDbCfgInfo
));
return
TSDB_CODE_SUCCESS
;
}
int32_t
reserveUserAuthInCache
(
int32_t
acctId
,
const
char
*
pUser
,
const
char
*
pDb
,
AUTH_TYPE
type
,
SParseMetaCache
*
pMetaCache
)
{
if
(
NULL
==
pMetaCache
->
pUserAuth
)
{
pMetaCache
->
pUserAuth
=
taosHashInit
(
4
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
if
(
NULL
==
pMetaCache
->
pUserAuth
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
char
key
[
USER_AUTH_KEY_MAX_LEN
]
=
{
0
};
int32_t
len
=
userAuthToString
(
acctId
,
pUser
,
pDb
,
type
,
key
);
bool
pass
=
false
;
return
taosHashPut
(
pMetaCache
->
pUserAuth
,
key
,
len
,
&
pass
,
sizeof
(
pass
));
}
int32_t
getUserAuthFromCache
(
SParseMetaCache
*
pMetaCache
,
const
char
*
pUser
,
const
char
*
pDbFName
,
AUTH_TYPE
type
,
bool
*
pPass
)
{
char
key
[
USER_AUTH_KEY_MAX_LEN
]
=
{
0
};
int32_t
len
=
userAuthToStringExt
(
pUser
,
pDbFName
,
type
,
key
);
bool
*
pRes
=
taosHashGet
(
pMetaCache
->
pUserAuth
,
key
,
len
);
if
(
NULL
==
pRes
)
{
return
TSDB_CODE_PAR_INTERNAL_ERROR
;
}
*
pPass
=
*
pRes
;
return
TSDB_CODE_SUCCESS
;
}
source/libs/parser/test/mockCatalogService.cpp
浏览文件 @
768beb64
...
...
@@ -131,6 +131,12 @@ class MockCatalogServiceImpl {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
getAllDbCfg
(
pCatalogReq
->
pDbCfg
,
&
pMetaData
->
pDbCfg
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
getAllDbInfo
(
pCatalogReq
->
pDbInfo
,
&
pMetaData
->
pDbInfo
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
getAllUserAuth
(
pCatalogReq
->
pUser
,
&
pMetaData
->
pUser
);
}
return
code
;
}
...
...
@@ -376,6 +382,32 @@ class MockCatalogServiceImpl {
return
code
;
}
int32_t
getAllDbInfo
(
SArray
*
pDbInfoReq
,
SArray
**
pDbInfoData
)
const
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
NULL
!=
pDbInfoReq
)
{
int32_t
ndbs
=
taosArrayGetSize
(
pDbInfoReq
);
*
pDbInfoData
=
taosArrayInit
(
ndbs
,
sizeof
(
SDbCfgInfo
));
for
(
int32_t
i
=
0
;
i
<
ndbs
;
++
i
)
{
SDbInfo
dbInfo
=
{
0
};
taosArrayPush
(
*
pDbInfoData
,
&
dbInfo
);
}
}
return
code
;
}
int32_t
getAllUserAuth
(
SArray
*
pUserAuthReq
,
SArray
**
pUserAuthData
)
const
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
NULL
!=
pUserAuthReq
)
{
int32_t
num
=
taosArrayGetSize
(
pUserAuthReq
);
*
pUserAuthData
=
taosArrayInit
(
num
,
sizeof
(
bool
));
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
bool
pass
=
true
;
taosArrayPush
(
*
pUserAuthData
,
&
pass
);
}
}
return
code
;
}
uint64_t
id_
;
std
::
unique_ptr
<
TableBuilder
>
builder_
;
DbMetaCache
meta_
;
...
...
source/libs/parser/test/parInitialDTest.cpp
浏览文件 @
768beb64
...
...
@@ -103,6 +103,7 @@ TEST_F(ParserInitialDTest, dropTopic) {
}
TEST_F
(
ParserInitialDTest
,
dropUser
)
{
login
(
"root"
);
useDb
(
"root"
,
"test"
);
run
(
"drop user wxy"
);
...
...
source/libs/parser/test/parTestUtil.cpp
浏览文件 @
768beb64
...
...
@@ -45,7 +45,7 @@ namespace ParserTest {
} while (0);
bool
g_dump
=
false
;
bool
g_testAsyncApis
=
fals
e
;
bool
g_testAsyncApis
=
tru
e
;
int32_t
g_logLevel
=
131
;
int32_t
g_skipSql
=
0
;
...
...
@@ -64,6 +64,8 @@ class ParserTestBaseImpl {
public:
ParserTestBaseImpl
(
ParserTestBase
*
pBase
)
:
pBase_
(
pBase
)
{}
void
login
(
const
std
::
string
&
user
)
{
caseEnv_
.
user_
=
user
;
}
void
useDb
(
const
string
&
acctId
,
const
string
&
db
)
{
caseEnv_
.
acctId_
=
acctId
;
caseEnv_
.
db_
=
db
;
...
...
@@ -84,6 +86,8 @@ class ParserTestBaseImpl {
SQuery
*
pQuery
=
nullptr
;
doParse
(
&
cxt
,
&
pQuery
);
doAuthenticate
(
&
cxt
,
pQuery
);
doTranslate
(
&
cxt
,
pQuery
);
doCalculateConstant
(
&
cxt
,
pQuery
);
...
...
@@ -107,8 +111,11 @@ class ParserTestBaseImpl {
private:
struct
caseEnv
{
string
acctId_
;
string
user_
;
string
db_
;
int32_t
nsql_
;
caseEnv
()
:
user_
(
"wangxiaoyu"
),
nsql_
(
0
)
{}
};
struct
stmtEnv
{
...
...
@@ -174,6 +181,8 @@ class ParserTestBaseImpl {
pCxt
->
acctId
=
atoi
(
caseEnv_
.
acctId_
.
c_str
());
pCxt
->
db
=
caseEnv_
.
db_
.
c_str
();
pCxt
->
pUser
=
caseEnv_
.
user_
.
c_str
();
pCxt
->
isSuperUser
=
caseEnv_
.
user_
==
"root"
;
pCxt
->
pSql
=
stmtEnv_
.
sql_
.
c_str
();
pCxt
->
sqlLen
=
stmtEnv_
.
sql_
.
length
();
pCxt
->
pMsg
=
stmtEnv_
.
msgBuf_
.
data
();
...
...
@@ -204,6 +213,8 @@ class ParserTestBaseImpl {
DO_WITH_THROW
(
putMetaDataToCache
,
pCatalogReq
,
pMetaData
,
pMetaCache
);
}
void
doAuthenticate
(
SParseContext
*
pCxt
,
SQuery
*
pQuery
)
{
DO_WITH_THROW
(
authenticate
,
pCxt
,
pQuery
);
}
void
doTranslate
(
SParseContext
*
pCxt
,
SQuery
*
pQuery
)
{
DO_WITH_THROW
(
translate
,
pCxt
,
pQuery
);
checkQuery
(
pQuery
,
PARSER_STAGE_TRANSLATE
);
...
...
@@ -248,6 +259,8 @@ class ParserTestBaseImpl {
doPutMetaDataToCache
(
&
catalogReq
,
&
metaData
,
pQuery
->
pMetaCache
);
doAuthenticate
(
&
cxt
,
pQuery
);
doTranslate
(
&
cxt
,
pQuery
);
doCalculateConstant
(
&
cxt
,
pQuery
);
...
...
@@ -287,6 +300,8 @@ ParserTestBase::ParserTestBase() : impl_(new ParserTestBaseImpl(this)) {}
ParserTestBase
::~
ParserTestBase
()
{}
void
ParserTestBase
::
login
(
const
std
::
string
&
user
)
{
return
impl_
->
login
(
user
);
}
void
ParserTestBase
::
useDb
(
const
std
::
string
&
acctId
,
const
std
::
string
&
db
)
{
impl_
->
useDb
(
acctId
,
db
);
}
void
ParserTestBase
::
run
(
const
std
::
string
&
sql
,
int32_t
expect
,
ParserStage
checkStage
)
{
...
...
source/libs/parser/test/parTestUtil.h
浏览文件 @
768beb64
...
...
@@ -34,6 +34,7 @@ class ParserTestBase : public testing::Test {
ParserTestBase
();
virtual
~
ParserTestBase
();
void
login
(
const
std
::
string
&
user
);
void
useDb
(
const
std
::
string
&
acctId
,
const
std
::
string
&
db
);
void
run
(
const
std
::
string
&
sql
,
int32_t
expect
=
TSDB_CODE_SUCCESS
,
ParserStage
checkStage
=
PARSER_STAGE_ALL
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录