Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
ddc13d29
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ddc13d29
编写于
1月 02, 2021
作者:
Y
yihaoDeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
share rpc obj
上级
1170afdb
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
99 addition
and
38 deletion
+99
-38
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+9
-1
src/client/src/tscSql.c
src/client/src/tscSql.c
+10
-6
src/client/src/tscSystem.c
src/client/src/tscSystem.c
+79
-25
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+1
-6
未找到文件。
src/client/inc/tsclient.h
浏览文件 @
ddc13d29
...
...
@@ -307,6 +307,7 @@ typedef struct STscObj {
struct
SSqlStream
*
streamList
;
SRpcCorEpSet
*
tscCorMgmtEpSet
;
void
*
pDnodeConn
;
void
*
pRpcObj
;
pthread_mutex_t
mutex
;
int32_t
numOfObj
;
// number of sqlObj from this tscObj
}
STscObj
;
...
...
@@ -377,7 +378,14 @@ typedef struct SSqlStream {
void
tscSetStreamDestTable
(
SSqlStream
*
pStream
,
const
char
*
dstTable
);
int32_t
tscInitRpc
(
const
char
*
user
,
const
char
*
secret
,
void
**
pDnodeConn
);
typedef
struct
{
char
key
[
512
];
void
*
pDnodeConn
;
}
SRpcObj
;
void
*
tscAcquireRpc
(
const
char
*
insKey
);
void
tscReleaseRpc
(
void
*
param
);
int32_t
tscInitRpc
(
const
char
*
key
,
const
char
*
user
,
const
char
*
secret
,
void
**
pRpcObj
,
void
**
pDnodeConn
);
void
tscInitMsgsFp
();
int
tsParseSql
(
SSqlObj
*
pSql
,
bool
initial
);
...
...
src/client/src/tscSql.c
浏览文件 @
ddc13d29
...
...
@@ -90,9 +90,12 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa
}
else
{
if
(
tscSetMgmtEpSetFromCfg
(
tsFirst
,
tsSecond
,
&
corMgmtEpSet
)
<
0
)
return
NULL
;
}
char
rpcKey
[
512
]
=
{
0
};
sprintf
(
rpcKey
,
"%s:%s:%s:%d"
,
user
,
pass
,
ip
,
port
);
void
*
pRpcObj
=
NULL
;
void
*
pDnodeConn
=
NULL
;
if
(
tscInitRpc
(
user
,
secretEncrypt
,
&
pDnodeConn
)
!=
0
)
{
if
(
tscInitRpc
(
rpcKey
,
user
,
secretEncrypt
,
&
pRpcObj
,
&
pDnodeConn
)
!=
0
)
{
terrno
=
TSDB_CODE_RPC_NETWORK_UNAVAIL
;
return
NULL
;
}
...
...
@@ -100,20 +103,21 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa
STscObj
*
pObj
=
(
STscObj
*
)
calloc
(
1
,
sizeof
(
STscObj
));
if
(
NULL
==
pObj
)
{
terrno
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
rpcClose
(
pDnodeConn
);
tscReleaseRpc
(
pRpcObj
);
return
NULL
;
}
// set up tscObj's mgmtEpSet
pObj
->
tscCorMgmtEpSet
=
(
SRpcCorEpSet
*
)
malloc
(
sizeof
(
SRpcCorEpSet
));
if
(
NULL
==
pObj
->
tscCorMgmtEpSet
)
{
terrno
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
rpcClose
(
pDnodeConn
);
tscReleaseRpc
(
pRpcObj
);
free
(
pObj
->
tscCorMgmtEpSet
);
free
(
pObj
);
}
memcpy
(
pObj
->
tscCorMgmtEpSet
,
&
corMgmtEpSet
,
sizeof
(
SRpcCorEpSet
));
pObj
->
signature
=
pObj
;
pObj
->
pRpcObj
=
pRpcObj
;
pObj
->
pDnodeConn
=
pDnodeConn
;
tstrncpy
(
pObj
->
user
,
user
,
sizeof
(
pObj
->
user
));
...
...
@@ -125,7 +129,7 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa
/* db name is too long */
if
(
len
>=
TSDB_DB_NAME_LEN
)
{
terrno
=
TSDB_CODE_TSC_INVALID_DB_LENGTH
;
rpcClose
(
pDnodeConn
);
tscReleaseRpc
(
pRpcObj
);
free
(
pObj
->
tscCorMgmtEpSet
);
free
(
pObj
);
return
NULL
;
...
...
@@ -143,7 +147,7 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa
SSqlObj
*
pSql
=
(
SSqlObj
*
)
calloc
(
1
,
sizeof
(
SSqlObj
));
if
(
NULL
==
pSql
)
{
terrno
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
rpcClose
(
pDnodeConn
);
tscReleaseRpc
(
pRpcObj
);
free
(
pObj
->
tscCorMgmtEpSet
);
free
(
pObj
);
return
NULL
;
...
...
@@ -160,7 +164,7 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa
if
(
TSDB_CODE_SUCCESS
!=
tscAllocPayload
(
&
pSql
->
cmd
,
TSDB_DEFAULT_PAYLOAD_SIZE
))
{
terrno
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
rpcClose
(
pDnodeConn
);
tscReleaseRpc
(
pRpcObj
);
free
(
pSql
);
free
(
pObj
->
tscCorMgmtEpSet
);
free
(
pObj
);
...
...
src/client/src/tscSystem.c
浏览文件 @
ddc13d29
...
...
@@ -40,39 +40,81 @@ void *tscCheckDiskUsageTmr;
int
tscRefId
=
-
1
;
int
tscNumOfObj
=
0
;
// number of sqlObj in current process.
int32_t
tscNumOfThreads
=
1
;
void
*
tscRpcCache
;
static
pthread_mutex_t
rpcObjMutex
;
static
pthread_once_t
tscinit
=
PTHREAD_ONCE_INIT
;
void
tscCheckDiskUsage
(
void
*
UNUSED_PARAM
(
para
),
void
*
UNUSED_PARAM
(
param
))
{
taosGetDisk
();
taosTmrReset
(
tscCheckDiskUsage
,
1000
,
NULL
,
tscTmr
,
&
tscCheckDiskUsageTmr
);
}
void
tscFreeRpcObj
(
void
*
param
)
{
assert
(
param
);
SRpcObj
*
pRpcObj
=
(
SRpcObj
*
)(
param
);
rpcClose
(
pRpcObj
->
pDnodeConn
);
}
void
*
tscAcquireRpc
(
const
char
*
key
)
{
SRpcObj
*
pRpcObj
=
taosCacheAcquireByKey
(
tscRpcCache
,
key
,
strlen
(
key
));
if
(
pRpcObj
==
NULL
)
{
return
NULL
;
}
return
pRpcObj
;
}
int32_t
tscInitRpc
(
const
char
*
user
,
const
char
*
secretEncrypt
,
void
**
pDnodeConn
)
{
SRpcInit
rpcInit
;
if
(
*
pDnodeConn
==
NULL
)
{
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
rpcInit
.
localPort
=
0
;
rpcInit
.
label
=
"TSC"
;
rpcInit
.
numOfThreads
=
1
;
// every DB connection has only one thread
rpcInit
.
cfp
=
tscProcessMsgFromServer
;
rpcInit
.
sessions
=
tsMaxConnections
;
rpcInit
.
connType
=
TAOS_CONN_CLIENT
;
rpcInit
.
user
=
(
char
*
)
user
;
rpcInit
.
idleTime
=
2000
;
rpcInit
.
ckey
=
"key"
;
rpcInit
.
spi
=
1
;
rpcInit
.
secret
=
(
char
*
)
secretEncrypt
;
*
pDnodeConn
=
rpcOpen
(
&
rpcInit
);
if
(
*
pDnodeConn
==
NULL
)
{
tscError
(
"failed to init connection to TDengine"
);
return
-
1
;
}
else
{
tscDebug
(
"dnodeConn:%p is created, user:%s"
,
*
pDnodeConn
,
user
);
}
void
tscReleaseRpc
(
void
*
param
)
{
if
(
param
==
NULL
)
{
return
;
}
pthread_mutex_lock
(
&
rpcObjMutex
);
taosCacheRelease
(
tscRpcCache
,
(
void
*
)
&
param
,
false
);
pthread_mutex_unlock
(
&
rpcObjMutex
);
}
int32_t
tscInitRpc
(
const
char
*
key
,
const
char
*
user
,
const
char
*
secretEncrypt
,
void
**
ppRpcObj
,
void
**
pDnodeConn
)
{
pthread_mutex_lock
(
&
rpcObjMutex
);
SRpcObj
*
pRpcObj
=
(
SRpcObj
*
)
tscAcquireRpc
(
key
);
if
(
pRpcObj
!=
NULL
)
{
*
ppRpcObj
=
pRpcObj
;
*
pDnodeConn
=
pRpcObj
->
pDnodeConn
;
pthread_mutex_unlock
(
&
rpcObjMutex
);
return
0
;
}
SRpcInit
rpcInit
;
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
rpcInit
.
localPort
=
0
;
rpcInit
.
label
=
"TSC"
;
rpcInit
.
numOfThreads
=
1
;
rpcInit
.
cfp
=
tscProcessMsgFromServer
;
rpcInit
.
sessions
=
tsMaxConnections
;
rpcInit
.
connType
=
TAOS_CONN_CLIENT
;
rpcInit
.
user
=
(
char
*
)
user
;
rpcInit
.
idleTime
=
2000
;
rpcInit
.
ckey
=
"key"
;
rpcInit
.
spi
=
1
;
rpcInit
.
secret
=
(
char
*
)
secretEncrypt
;
SRpcObj
rpcObj
;
memset
(
&
rpcObj
,
0
,
sizeof
(
rpcObj
));
strncpy
(
rpcObj
.
key
,
key
,
strlen
(
key
));
rpcObj
.
pDnodeConn
=
rpcOpen
(
&
rpcInit
);
if
(
rpcObj
.
pDnodeConn
==
NULL
)
{
pthread_mutex_unlock
(
&
rpcObjMutex
);
tscError
(
"failed to init connection to TDengine"
);
return
-
1
;
}
pRpcObj
=
taosCachePut
(
tscRpcCache
,
rpcObj
.
key
,
strlen
(
rpcObj
.
key
),
&
rpcObj
,
sizeof
(
rpcObj
),
1000
*
10
);
if
(
pRpcObj
==
NULL
)
{
rpcClose
(
rpcObj
.
pDnodeConn
);
pthread_mutex_unlock
(
&
rpcObjMutex
);
return
-
1
;
}
*
ppRpcObj
=
pRpcObj
;
*
pDnodeConn
=
pRpcObj
->
pDnodeConn
;
pthread_mutex_unlock
(
&
rpcObjMutex
);
return
0
;
}
...
...
@@ -113,7 +155,7 @@ void taos_init_imp(void) {
int
queueSize
=
tsMaxConnections
*
2
;
double
factor
=
(
tscEmbedded
==
0
)
?
2
.
0
:
4
.
0
;
int32_t
tscNumOfThreads
=
(
int
)(
tsNumOfCores
*
tsNumOfThreadsPerCore
/
factor
);
tscNumOfThreads
=
(
int
)(
tsNumOfCores
*
tsNumOfThreadsPerCore
/
factor
);
if
(
tscNumOfThreads
<
2
)
{
tscNumOfThreads
=
2
;
}
...
...
@@ -135,6 +177,8 @@ void taos_init_imp(void) {
tscObjRef
=
taosOpenRef
(
40960
,
tscFreeRegisteredSqlObj
);
tscHashMap
=
taosHashInit
(
1024
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
true
,
HASH_ENTRY_LOCK
);
}
tscRpcCache
=
taosCacheInit
(
TSDB_DATA_TYPE_BINARY
,
refreshTime
,
true
,
tscFreeRpcObj
,
"rpcObj"
);
pthread_mutex_init
(
&
rpcObjMutex
,
NULL
);
tscRefId
=
taosOpenRef
(
200
,
tscCloseTscObj
);
...
...
@@ -169,6 +213,16 @@ void taos_cleanup(void) {
taosCloseRef
(
tscRefId
);
taosCleanupKeywordsTable
();
taosCloseLog
();
m
=
tscRpcCache
;
if
(
m
!=
NULL
&&
atomic_val_compare_exchange_ptr
(
&
tscRpcCache
,
m
,
0
)
==
m
)
{
pthread_mutex_lock
(
&
rpcObjMutex
);
taosCacheCleanup
(
tscRpcCache
);
tscRpcCache
=
NULL
;
pthread_mutex_unlock
(
&
rpcObjMutex
);
pthread_mutex_destroy
(
&
rpcObjMutex
);
}
if
(
tscEmbedded
==
0
)
rpcCleanup
();
m
=
tscTmr
;
...
...
src/client/src/tscUtil.c
浏览文件 @
ddc13d29
...
...
@@ -895,15 +895,10 @@ void tscCloseTscObj(void *param) {
pObj
->
signature
=
NULL
;
taosTmrStopA
(
&
(
pObj
->
pTimer
));
void
*
p
=
pObj
->
pDnodeConn
;
if
(
pObj
->
pDnodeConn
!=
NULL
)
{
rpcClose
(
pObj
->
pDnodeConn
);
pObj
->
pDnodeConn
=
NULL
;
}
tscReleaseRpc
(
pObj
->
pRpcObj
);
tfree
(
pObj
->
tscCorMgmtEpSet
);
pthread_mutex_destroy
(
&
pObj
->
mutex
);
tscDebug
(
"%p DB connection is closed, dnodeConn:%p"
,
pObj
,
p
);
tfree
(
pObj
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录