Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
209f3db8
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1185
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
209f3db8
编写于
6月 15, 2020
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-637] cleanup cache in callback function
上级
73f2baac
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
50 addition
and
31 deletion
+50
-31
src/mnode/src/mnodeProfile.c
src/mnode/src/mnodeProfile.c
+1
-1
src/plugins/http/inc/httpContext.h
src/plugins/http/inc/httpContext.h
+1
-1
src/plugins/http/src/httpContext.c
src/plugins/http/src/httpContext.c
+17
-13
src/plugins/http/src/httpServer.c
src/plugins/http/src/httpServer.c
+2
-2
src/plugins/http/src/httpSession.c
src/plugins/http/src/httpSession.c
+14
-11
src/plugins/http/src/httpSystem.c
src/plugins/http/src/httpSystem.c
+1
-1
src/util/src/tcache.c
src/util/src/tcache.c
+14
-2
未找到文件。
src/mnode/src/mnodeProfile.c
浏览文件 @
209f3db8
...
...
@@ -138,7 +138,7 @@ SConnObj *mnodeAccquireConn(uint32_t connId, char *user, uint32_t ip, uint16_t p
static
void
mnodeFreeConn
(
void
*
data
)
{
SConnObj
*
pConn
=
data
;
tfree
(
pConn
->
pQueries
);
tfree
(
pConn
->
p
Querie
s
);
tfree
(
pConn
->
p
Stream
s
);
mTrace
(
"connId:%d, is destroyed"
,
pConn
->
connId
);
}
...
...
src/plugins/http/inc/httpContext.h
浏览文件 @
209f3db8
...
...
@@ -24,7 +24,7 @@ const char *httpContextStateStr(HttpContextState state);
HttpContext
*
httpCreateContext
(
int32_t
fd
);
bool
httpInitContext
(
HttpContext
*
pContext
);
HttpContext
*
httpGetContext
(
int32_t
fd
);
HttpContext
*
httpGetContext
(
void
*
pContext
);
void
httpReleaseContext
(
HttpContext
*
pContext
);
void
httpCloseContextByServer
(
HttpContext
*
pContext
);
void
httpCloseContextByApp
(
HttpContext
*
pContext
);
...
...
src/plugins/http/src/httpContext.c
浏览文件 @
209f3db8
...
...
@@ -22,6 +22,7 @@
#include "ttimer.h"
#include "tglobal.h"
#include "tcache.h"
#include "hash.h"
#include "httpInt.h"
#include "httpResp.h"
#include "httpSql.h"
...
...
@@ -38,15 +39,13 @@ static void httpRemoveContextFromEpoll(HttpContext *pContext) {
static
void
httpDestroyContext
(
void
*
data
)
{
HttpContext
*
pContext
=
*
(
HttpContext
**
)
data
;
httpTrace
(
"context:%p, is destroyed, refCount:%d"
,
pContext
,
pContext
->
refCount
);
if
(
pContext
->
fd
>
0
)
tclose
(
pContext
->
fd
);
HttpThread
*
pThread
=
pContext
->
pThread
;
httpRemoveContextFromEpoll
(
pContext
);
httpReleaseSession
(
pContext
);
atomic_sub_fetch_32
(
&
pThread
->
numOfFds
,
1
);
pContext
->
pThread
=
0
;
pContext
->
state
=
HTTP_CONTEXT_STATE_CLOSED
;
...
...
@@ -54,11 +53,12 @@ static void httpDestroyContext(void *data) {
httpFreeJsonBuf
(
pContext
);
httpFreeMultiCmds
(
pContext
);
httpTrace
(
"context:%p, is destroyed, refCount:%d"
,
pContext
,
pContext
->
refCount
);
tfree
(
pContext
);
}
bool
httpInitContexts
()
{
tsHttpServer
.
contextCache
=
taosCacheInitWithCb
(
5
,
httpDestroyContext
);
tsHttpServer
.
contextCache
=
taosCacheInitWithCb
(
2
,
httpDestroyContext
);
if
(
tsHttpServer
.
contextCache
==
NULL
)
{
httpError
(
"failed to init context cache"
);
return
false
;
...
...
@@ -70,7 +70,8 @@ bool httpInitContexts() {
void
httpCleanupContexts
()
{
// TODO: wait until all context is closed
if
(
tsHttpServer
.
contextCache
!=
NULL
)
{
httpPrint
(
"context cache is cleanup"
);
SCacheObj
*
cache
=
tsHttpServer
.
contextCache
;
httpPrint
(
"context cache is cleanuping, size:%d"
,
taosHashGetSize
(
cache
->
pHashTable
));
taosCacheCleanup
(
tsHttpServer
.
contextCache
);
tsHttpServer
.
contextCache
=
NULL
;
}
...
...
@@ -103,26 +104,29 @@ HttpContext *httpCreateContext(int32_t fd) {
HttpContext
*
pContext
=
calloc
(
1
,
sizeof
(
HttpContext
));
if
(
pContext
==
NULL
)
return
NULL
;
char
fdStr
[
12
]
=
{
0
};
snprintf
(
fdStr
,
sizeof
(
fdStr
),
"%d"
,
fd
);
char
contextStr
[
16
]
=
{
0
};
snprintf
(
contextStr
,
sizeof
(
contextStr
),
"%p"
,
pContext
);
pContext
->
fd
=
fd
;
pContext
->
httpVersion
=
HTTP_VERSION_10
;
pContext
->
lastAccessTime
=
taosGetTimestampSec
();
pContext
->
state
=
HTTP_CONTEXT_STATE_READY
;
HttpContext
**
ppContext
=
taosCachePut
(
tsHttpServer
.
contextCache
,
fdStr
,
&
pContext
,
sizeof
(
HttpContext
*
),
5
);
HttpContext
**
ppContext
=
taosCachePut
(
tsHttpServer
.
contextCache
,
contextStr
,
&
pContext
,
sizeof
(
HttpContext
*
),
3
);
pContext
->
ppContext
=
ppContext
;
httpTrace
(
"context:%p, fd:%d, is created"
,
pContext
,
fd
);
httpTrace
(
"context:%p, fd:%d, is created, item:%p"
,
pContext
,
fd
,
ppContext
);
// set the ref to 0
taosCacheRelease
(
tsHttpServer
.
contextCache
,
(
void
**
)
&
ppContext
,
false
);
return
pContext
;
}
HttpContext
*
httpGetContext
(
int32_t
fd
)
{
char
fdStr
[
12
]
=
{
0
};
snprintf
(
fdStr
,
sizeof
(
fdStr
),
"%d"
,
fd
);
HttpContext
*
httpGetContext
(
void
*
ptr
)
{
char
contextStr
[
16
]
=
{
0
};
snprintf
(
contextStr
,
sizeof
(
contextStr
),
"%p"
,
ptr
);
HttpContext
**
ppContext
=
taosCacheAcquireByName
(
tsHttpServer
.
contextCache
,
fd
Str
);
HttpContext
**
ppContext
=
taosCacheAcquireByName
(
tsHttpServer
.
contextCache
,
context
Str
);
if
(
ppContext
)
{
HttpContext
*
pContext
=
*
ppContext
;
...
...
src/plugins/http/src/httpServer.c
浏览文件 @
209f3db8
...
...
@@ -193,7 +193,7 @@ static void httpProcessHttpData(void *param) {
if
(
fdNum
<=
0
)
continue
;
for
(
int
i
=
0
;
i
<
fdNum
;
++
i
)
{
pContext
=
httpGetContext
(
events
[
i
].
data
.
fd
);
pContext
=
httpGetContext
(
events
[
i
].
data
.
ptr
);
if
(
pContext
==
NULL
)
{
httpError
(
"fd:%d, is already released, close connect"
,
events
[
i
].
data
.
fd
);
epoll_ctl
(
pThread
->
pollFd
,
EPOLL_CTL_DEL
,
pContext
->
fd
,
NULL
);
...
...
@@ -319,7 +319,7 @@ static void *httpAcceptHttpConnection(void *arg) {
struct
epoll_event
event
;
event
.
events
=
EPOLLIN
|
EPOLLPRI
|
EPOLLWAKEUP
|
EPOLLERR
|
EPOLLHUP
|
EPOLLRDHUP
;
event
.
data
.
fd
=
connFd
;
event
.
data
.
ptr
=
pContext
;
if
(
epoll_ctl
(
pThread
->
pollFd
,
EPOLL_CTL_ADD
,
connFd
,
&
event
)
<
0
)
{
httpError
(
"context:%p, fd:%d, ip:%s, thread:%s, failed to add http fd for epoll, error:%s"
,
pContext
,
connFd
,
pContext
->
ipstr
,
pThread
->
label
,
strerror
(
errno
));
...
...
src/plugins/http/src/httpSession.c
浏览文件 @
209f3db8
...
...
@@ -35,6 +35,8 @@ void httpCreateSession(HttpContext *pContext, void *taos) {
snprintf
(
session
.
id
,
HTTP_SESSION_ID_LEN
,
"%s.%s"
,
pContext
->
user
,
pContext
->
pass
);
pContext
->
session
=
taosCachePut
(
server
->
sessionCache
,
session
.
id
,
&
session
,
sizeof
(
HttpSession
),
tsHttpSessionExpire
);
// void *temp = pContext->session;
// taosCacheRelease(server->sessionCache, (void **)&temp, false);
if
(
pContext
->
session
==
NULL
)
{
httpError
(
"context:%p, fd:%d, ip:%s, user:%s, error:%s"
,
pContext
,
pContext
->
fd
,
pContext
->
ipstr
,
pContext
->
user
,
...
...
@@ -44,7 +46,7 @@ void httpCreateSession(HttpContext *pContext, void *taos) {
return
;
}
httpTrace
(
"context:%p, fd:%d, ip:%s, user:%s, create a new session:%p:%p
refCount
:%d"
,
pContext
,
pContext
->
fd
,
httpTrace
(
"context:%p, fd:%d, ip:%s, user:%s, create a new session:%p:%p
sessionRef
:%d"
,
pContext
,
pContext
->
fd
,
pContext
->
ipstr
,
pContext
->
user
,
pContext
->
session
,
pContext
->
session
->
taos
,
pContext
->
session
->
refCount
);
pthread_mutex_unlock
(
&
server
->
serverMutex
);
}
...
...
@@ -59,7 +61,7 @@ static void httpFetchSessionImp(HttpContext *pContext) {
pContext
->
session
=
taosCacheAcquireByName
(
server
->
sessionCache
,
sessionId
);
if
(
pContext
->
session
!=
NULL
)
{
atomic_add_fetch_32
(
&
pContext
->
session
->
refCount
,
1
);
httpTrace
(
"context:%p, fd:%d, ip:%s, user:%s, find an exist session:%p:%p,
refCount
:%d"
,
pContext
,
pContext
->
fd
,
httpTrace
(
"context:%p, fd:%d, ip:%s, user:%s, find an exist session:%p:%p,
sessionRef
:%d"
,
pContext
,
pContext
->
fd
,
pContext
->
ipstr
,
pContext
->
user
,
pContext
->
session
,
pContext
->
session
->
taos
,
pContext
->
session
->
refCount
);
}
else
{
httpTrace
(
"context:%p, fd:%d, ip:%s, user:%s, session not found"
,
pContext
,
pContext
->
fd
,
pContext
->
ipstr
,
...
...
@@ -85,26 +87,27 @@ void httpReleaseSession(HttpContext *pContext) {
int32_t
refCount
=
atomic_sub_fetch_32
(
&
pContext
->
session
->
refCount
,
1
);
assert
(
refCount
>=
0
);
httpTrace
(
"context:%p, session:%p is releasd refCount:%d"
,
pContext
,
pContext
->
session
,
pContext
->
session
->
refCount
);
httpTrace
(
"context:%p, release session:%p:%p, sessionRef:%d"
,
pContext
,
pContext
->
session
,
pContext
->
session
->
taos
,
pContext
->
session
->
refCount
);
taosCacheRelease
(
tsHttpServer
.
sessionCache
,
(
void
**
)(
&
(
pContext
->
session
))
,
false
);
taosCacheRelease
(
tsHttpServer
.
sessionCache
,
(
void
**
)
&
pContext
->
session
,
false
);
pContext
->
session
=
NULL
;
}
static
void
httpDestroySession
(
void
*
data
)
{
HttpSession
*
pS
ession
=
data
;
httpTrace
(
"session:%p:%p, is destroyed,
refCount:%d"
,
pSession
,
pSession
->
taos
,
pS
ession
->
refCount
);
HttpSession
*
s
ession
=
data
;
httpTrace
(
"session:%p:%p, is destroyed,
sessionRef:%d"
,
session
,
session
->
taos
,
s
ession
->
refCount
);
if
(
pS
ession
->
taos
!=
NULL
)
{
taos_close
(
pS
ession
->
taos
);
pS
ession
->
taos
=
NULL
;
if
(
s
ession
->
taos
!=
NULL
)
{
taos_close
(
s
ession
->
taos
);
s
ession
->
taos
=
NULL
;
}
tfree
(
pSession
);
}
void
httpCleanUpSessions
()
{
if
(
tsHttpServer
.
sessionCache
!=
NULL
)
{
httpPrint
(
"session cache is cleanup"
);
SCacheObj
*
cache
=
tsHttpServer
.
sessionCache
;
httpPrint
(
"session cache is cleanuping, size:%d"
,
taosHashGetSize
(
cache
->
pHashTable
));
taosCacheCleanup
(
tsHttpServer
.
sessionCache
);
tsHttpServer
.
sessionCache
=
NULL
;
}
...
...
src/plugins/http/src/httpSystem.c
浏览文件 @
209f3db8
...
...
@@ -92,7 +92,7 @@ void httpStopSystem() {
}
void
httpCleanUpSystem
()
{
httpPrint
(
"http serv
ice
cleanup"
);
httpPrint
(
"http serv
er
cleanup"
);
httpStopSystem
();
httpCleanupContexts
();
...
...
src/util/src/tcache.c
浏览文件 @
209f3db8
...
...
@@ -63,10 +63,12 @@ static FORCE_INLINE void __cache_lock_destroy(SCacheObj *pCacheObj) {
#endif
}
#if 0
static FORCE_INLINE void taosFreeNode(void *data) {
SCacheDataNode *pNode = *(SCacheDataNode **)data;
free(pNode);
}
#endif
/**
* @param key key of object for hash, usually a null-terminated string
...
...
@@ -241,7 +243,7 @@ SCacheObj *taosCacheInitWithCb(int64_t refreshTime, void (*freeCb)(void *data))
}
// set free cache node callback function for hash table
taosHashSetFreecb
(
pCacheObj
->
pHashTable
,
taosFreeNode
);
//
taosHashSetFreecb(pCacheObj->pHashTable, taosFreeNode);
pCacheObj
->
freeFp
=
freeCb
;
pCacheObj
->
refreshTime
=
refreshTime
*
1000
;
...
...
@@ -565,7 +567,17 @@ void taosTrashCanEmpty(SCacheObj *pCacheObj, bool force) {
void
doCleanupDataCache
(
SCacheObj
*
pCacheObj
)
{
__cache_wr_lock
(
pCacheObj
);
taosHashCleanup
(
pCacheObj
->
pHashTable
);
SHashMutableIterator
*
pIter
=
taosHashCreateIter
(
pCacheObj
->
pHashTable
);
while
(
taosHashIterNext
(
pIter
))
{
SCacheDataNode
*
pNode
=
*
(
SCacheDataNode
**
)
taosHashIterGet
(
pIter
);
// if (pNode->expiredTime <= expiredTime && T_REF_VAL_GET(pNode) <= 0) {
taosCacheReleaseNode
(
pCacheObj
,
pNode
);
//}
}
taosHashDestroyIter
(
pIter
);
taosHashCleanup
(
pCacheObj
->
pHashTable
);
__cache_unlock
(
pCacheObj
);
taosTrashCanEmpty
(
pCacheObj
,
true
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录