Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d8cfe2d3
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1185
Star
22015
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看板
未验证
提交
d8cfe2d3
编写于
7月 03, 2020
作者:
S
Shengliang Guan
提交者:
GitHub
7月 03, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2553 from taosdata/hotfix/crash
Hotfix/crash
上级
6e8c7917
56263126
变更
11
显示空白变更内容
内联
并排
Showing
11 changed file
with
78 addition
and
80 deletion
+78
-80
src/client/src/tscSystem.c
src/client/src/tscSystem.c
+1
-1
src/mnode/inc/mnodeProfile.h
src/mnode/inc/mnodeProfile.h
+1
-1
src/mnode/src/mnodeProfile.c
src/mnode/src/mnodeProfile.c
+12
-14
src/mnode/src/mnodeShow.c
src/mnode/src/mnodeShow.c
+4
-10
src/plugins/http/src/httpContext.c
src/plugins/http/src/httpContext.c
+10
-15
src/plugins/http/src/httpSession.c
src/plugins/http/src/httpSession.c
+1
-1
src/util/inc/tcache.h
src/util/inc/tcache.h
+4
-3
src/util/src/tcache.c
src/util/src/tcache.c
+39
-30
src/util/tests/cacheTest.cpp
src/util/tests/cacheTest.cpp
+2
-2
src/vnode/src/vnodeMain.c
src/vnode/src/vnodeMain.c
+1
-1
tests/script/sh/deploy.sh
tests/script/sh/deploy.sh
+3
-2
未找到文件。
src/client/src/tscSystem.c
浏览文件 @
d8cfe2d3
...
...
@@ -148,7 +148,7 @@ void taos_init_imp() {
refreshTime
=
refreshTime
<
10
?
10
:
refreshTime
;
if
(
tscCacheHandle
==
NULL
)
{
tscCacheHandle
=
taosCacheInit
(
TSDB_DATA_TYPE_BINARY
,
refreshTime
,
false
,
NULL
);
tscCacheHandle
=
taosCacheInit
(
TSDB_DATA_TYPE_BINARY
,
refreshTime
,
false
,
NULL
,
"client"
);
}
tscDebug
(
"client is initialized successfully"
);
...
...
src/mnode/inc/mnodeProfile.h
浏览文件 @
d8cfe2d3
...
...
@@ -41,7 +41,7 @@ int32_t mnodeInitProfile();
void
mnodeCleanupProfile
();
SConnObj
*
mnodeCreateConn
(
char
*
user
,
uint32_t
ip
,
uint16_t
port
);
SConnObj
*
mnodeAccquireConn
(
u
int32_t
connId
,
char
*
user
,
uint32_t
ip
,
uint16_t
port
);
SConnObj
*
mnodeAccquireConn
(
int32_t
connId
,
char
*
user
,
uint32_t
ip
,
uint16_t
port
);
void
mnodeReleaseConn
(
SConnObj
*
pConn
);
int32_t
mnodeSaveQueryStreamList
(
SConnObj
*
pConn
,
SCMHeartBeatMsg
*
pHBMsg
);
...
...
src/mnode/src/mnodeProfile.c
浏览文件 @
d8cfe2d3
...
...
@@ -43,7 +43,7 @@
extern
void
*
tsMnodeTmr
;
static
SCacheObj
*
tsMnodeConnCache
=
NULL
;
static
u
int32_t
tsConnIndex
=
0
;
static
int32_t
tsConnIndex
=
0
;
static
int32_t
mnodeGetQueryMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
mnodeRetrieveQueries
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
...
...
@@ -68,7 +68,7 @@ int32_t mnodeInitProfile() {
mnodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_KILL_STREAM
,
mnodeProcessKillStreamMsg
);
mnodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_KILL_CONN
,
mnodeProcessKillConnectionMsg
);
tsMnodeConnCache
=
taosCacheInitWithCb
(
TSDB_DATA_TYPE_
BINARY
,
CONN_CHECK_TIME
,
false
,
mnodeFreeConn
);
tsMnodeConnCache
=
taosCacheInitWithCb
(
TSDB_DATA_TYPE_
INT
,
CONN_CHECK_TIME
,
false
,
mnodeFreeConn
,
"conn"
);
return
0
;
}
...
...
@@ -89,7 +89,7 @@ SConnObj *mnodeCreateConn(char *user, uint32_t ip, uint16_t port) {
return
NULL
;
}
u
int32_t
connId
=
atomic_add_fetch_32
(
&
tsConnIndex
,
1
);
int32_t
connId
=
atomic_add_fetch_32
(
&
tsConnIndex
,
1
);
if
(
connId
==
0
)
atomic_add_fetch_32
(
&
tsConnIndex
,
1
);
SConnObj
connObj
=
{
...
...
@@ -100,9 +100,7 @@ SConnObj *mnodeCreateConn(char *user, uint32_t ip, uint16_t port) {
};
tstrncpy
(
connObj
.
user
,
user
,
sizeof
(
connObj
.
user
));
char
key
[
10
];
int32_t
len
=
sprintf
(
key
,
"%u"
,
connId
);
SConnObj
*
pConn
=
taosCachePut
(
tsMnodeConnCache
,
key
,
len
,
&
connObj
,
sizeof
(
connObj
),
CONN_KEEP_TIME
);
SConnObj
*
pConn
=
taosCachePut
(
tsMnodeConnCache
,
&
connId
,
sizeof
(
int32_t
),
&
connObj
,
sizeof
(
connObj
),
CONN_KEEP_TIME
);
mDebug
(
"connId:%d, is created, user:%s ip:%s:%u"
,
connId
,
user
,
taosIpStr
(
ip
),
port
);
return
pConn
;
...
...
@@ -113,12 +111,9 @@ void mnodeReleaseConn(SConnObj *pConn) {
taosCacheRelease
(
tsMnodeConnCache
,
(
void
**
)
&
pConn
,
false
);
}
SConnObj
*
mnodeAccquireConn
(
uint32_t
connId
,
char
*
user
,
uint32_t
ip
,
uint16_t
port
)
{
char
key
[
10
];
int32_t
len
=
sprintf
(
key
,
"%u"
,
connId
);
SConnObj
*
mnodeAccquireConn
(
int32_t
connId
,
char
*
user
,
uint32_t
ip
,
uint16_t
port
)
{
uint64_t
expireTime
=
CONN_KEEP_TIME
*
1000
+
(
uint64_t
)
taosGetTimestampMs
();
SConnObj
*
pConn
=
taosCacheUpdateExpireTimeByName
(
tsMnodeConnCache
,
key
,
len
,
expireTime
);
SConnObj
*
pConn
=
taosCacheUpdateExpireTimeByName
(
tsMnodeConnCache
,
&
connId
,
sizeof
(
int32_t
),
expireTime
);
if
(
pConn
==
NULL
)
{
mError
(
"connId:%d, is already destroyed, user:%s ip:%s:%u"
,
connId
,
user
,
taosIpStr
(
ip
),
port
);
return
NULL
;
...
...
@@ -547,7 +542,8 @@ static int32_t mnodeProcessKillQueryMsg(SMnodeMsg *pMsg) {
int32_t
queryId
=
(
int32_t
)
strtol
(
queryIdStr
,
NULL
,
10
);
SConnObj
*
pConn
=
taosCacheAcquireByKey
(
tsMnodeConnCache
,
connIdStr
,
strlen
(
connIdStr
));
int32_t
connId
=
atoi
(
connIdStr
);
SConnObj
*
pConn
=
taosCacheAcquireByKey
(
tsMnodeConnCache
,
&
connId
,
sizeof
(
int32_t
));
if
(
pConn
==
NULL
)
{
mError
(
"connId:%s, failed to kill queryId:%d, conn not exist"
,
connIdStr
,
queryId
);
return
TSDB_CODE_MND_INVALID_CONN_ID
;
...
...
@@ -576,8 +572,9 @@ static int32_t mnodeProcessKillStreamMsg(SMnodeMsg *pMsg) {
}
int32_t
streamId
=
(
int32_t
)
strtol
(
streamIdStr
,
NULL
,
10
);
int32_t
connId
=
atoi
(
connIdStr
);
SConnObj
*
pConn
=
taosCacheAcquireByKey
(
tsMnodeConnCache
,
connIdStr
,
strlen
(
connIdStr
));
SConnObj
*
pConn
=
taosCacheAcquireByKey
(
tsMnodeConnCache
,
&
connId
,
sizeof
(
int32_t
));
if
(
pConn
==
NULL
)
{
mError
(
"connId:%s, failed to kill streamId:%d, conn not exist"
,
connIdStr
,
streamId
);
return
TSDB_CODE_MND_INVALID_CONN_ID
;
...
...
@@ -594,7 +591,8 @@ static int32_t mnodeProcessKillConnectionMsg(SMnodeMsg *pMsg) {
if
(
strcmp
(
pUser
->
user
,
TSDB_DEFAULT_USER
)
!=
0
)
return
TSDB_CODE_MND_NO_RIGHTS
;
SCMKillConnMsg
*
pKill
=
pMsg
->
rpcMsg
.
pCont
;
SConnObj
*
pConn
=
taosCacheAcquireByKey
(
tsMnodeConnCache
,
pKill
->
queryId
,
strlen
(
pKill
->
queryId
));
int32_t
connId
=
atoi
(
pKill
->
queryId
);
SConnObj
*
pConn
=
taosCacheAcquireByKey
(
tsMnodeConnCache
,
&
connId
,
sizeof
(
int32_t
));
if
(
pConn
==
NULL
)
{
mError
(
"connId:%s, failed to kill, conn not exist"
,
pKill
->
queryId
);
return
TSDB_CODE_MND_INVALID_CONN_ID
;
...
...
src/mnode/src/mnodeShow.c
浏览文件 @
d8cfe2d3
...
...
@@ -65,7 +65,7 @@ int32_t mnodeInitShow() {
mnodeAddReadMsgHandle
(
TSDB_MSG_TYPE_CM_CONNECT
,
mnodeProcessConnectMsg
);
mnodeAddReadMsgHandle
(
TSDB_MSG_TYPE_CM_USE_DB
,
mnodeProcessUseMsg
);
tsMnodeShowCache
=
taosCacheInitWithCb
(
TSDB_DATA_TYPE_
BINARY
,
5
,
false
,
mnodeFreeShowObj
);
tsMnodeShowCache
=
taosCacheInitWithCb
(
TSDB_DATA_TYPE_
INT
,
5
,
false
,
mnodeFreeShowObj
,
"show"
);
return
0
;
}
...
...
@@ -364,10 +364,7 @@ static bool mnodeCheckShowFinished(SShowObj *pShow) {
}
static
bool
mnodeAccquireShowObj
(
SShowObj
*
pShow
)
{
char
key
[
10
];
int32_t
len
=
sprintf
(
key
,
"%d"
,
pShow
->
index
);
SShowObj
*
pSaved
=
taosCacheAcquireByKey
(
tsMnodeShowCache
,
key
,
len
);
SShowObj
*
pSaved
=
taosCacheAcquireByKey
(
tsMnodeShowCache
,
&
pShow
->
index
,
sizeof
(
int32_t
));
if
(
pSaved
==
pShow
)
{
mDebug
(
"%p, show is accquired from cache"
,
pShow
);
return
true
;
...
...
@@ -378,14 +375,11 @@ static bool mnodeAccquireShowObj(SShowObj *pShow) {
static
void
*
mnodePutShowObj
(
SShowObj
*
pShow
,
int32_t
size
)
{
if
(
tsMnodeShowCache
!=
NULL
)
{
char
key
[
10
];
pShow
->
index
=
atomic_add_fetch_32
(
&
tsShowObjIndex
,
1
);
int32_t
len
=
sprintf
(
key
,
"%d"
,
pShow
->
index
);
SShowObj
*
newQhandle
=
taosCachePut
(
tsMnodeShowCache
,
key
,
len
,
pShow
,
size
,
6
);
SShowObj
*
newQhandle
=
taosCachePut
(
tsMnodeShowCache
,
&
pShow
->
index
,
sizeof
(
int32_t
),
pShow
,
size
,
6
);
free
(
pShow
);
mDebug
(
"%p, show is put into cache, index:%
s"
,
newQhandle
,
key
);
mDebug
(
"%p, show is put into cache, index:%
d"
,
newQhandle
,
pShow
->
index
);
return
newQhandle
;
}
...
...
src/plugins/http/src/httpContext.c
浏览文件 @
d8cfe2d3
...
...
@@ -53,12 +53,12 @@ static void httpDestroyContext(void *data) {
httpFreeJsonBuf
(
pContext
);
httpFreeMultiCmds
(
pContext
);
httpDebug
(
"context:%p, is destroyed, refCount:%d
"
,
pContext
,
pContext
->
refCount
);
httpDebug
(
"context:%p, is destroyed, refCount:%d
data:%p"
,
pContext
,
pContext
->
refCount
,
data
);
tfree
(
pContext
);
}
bool
httpInitContexts
()
{
tsHttpServer
.
contextCache
=
taosCacheInitWithCb
(
TSDB_DATA_TYPE_BI
NARY
,
2
,
false
,
httpDestroyContext
);
tsHttpServer
.
contextCache
=
taosCacheInitWithCb
(
TSDB_DATA_TYPE_BI
GINT
,
2
,
false
,
httpDestroyContext
,
"restc"
);
if
(
tsHttpServer
.
contextCache
==
NULL
)
{
httpError
(
"failed to init context cache"
);
return
false
;
...
...
@@ -103,17 +103,14 @@ HttpContext *httpCreateContext(int32_t fd) {
HttpContext
*
pContext
=
calloc
(
1
,
sizeof
(
HttpContext
));
if
(
pContext
==
NULL
)
return
NULL
;
char
contextStr
[
16
]
=
{
0
};
int32_t
keySize
=
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
,
contextStr
,
keySize
,
&
pContext
,
sizeof
(
HttpContext
*
),
3
);
HttpContext
**
ppContext
=
taosCachePut
(
tsHttpServer
.
contextCache
,
&
pContext
,
sizeof
(
void
*
),
&
pContext
,
sizeof
(
void
*
),
3
);
pContext
->
ppContext
=
ppContext
;
httpDebug
(
"context:%p, fd:%d, is created,
item
:%p"
,
pContext
,
fd
,
ppContext
);
httpDebug
(
"context:%p, fd:%d, is created,
data
:%p"
,
pContext
,
fd
,
ppContext
);
// set the ref to 0
taosCacheRelease
(
tsHttpServer
.
contextCache
,
(
void
**
)
&
ppContext
,
false
);
...
...
@@ -122,16 +119,13 @@ HttpContext *httpCreateContext(int32_t fd) {
}
HttpContext
*
httpGetContext
(
void
*
ptr
)
{
char
contextStr
[
16
]
=
{
0
};
int32_t
len
=
snprintf
(
contextStr
,
sizeof
(
contextStr
),
"%p"
,
ptr
);
HttpContext
**
ppContext
=
taosCacheAcquireByKey
(
tsHttpServer
.
contextCache
,
contextStr
,
len
);
HttpContext
**
ppContext
=
taosCacheAcquireByKey
(
tsHttpServer
.
contextCache
,
&
ptr
,
sizeof
(
HttpContext
*
));
if
(
ppContext
)
{
HttpContext
*
pContext
=
*
ppContext
;
if
(
pContext
)
{
int32_t
refCount
=
atomic_add_fetch_32
(
&
pContext
->
refCount
,
1
);
httpDebug
(
"context:%p, fd:%d, is accquired,
refCount:%d"
,
pContext
,
pContext
->
fd
,
refCount
);
httpDebug
(
"context:%p, fd:%d, is accquired,
data:%p refCount:%d"
,
pContext
,
pContext
->
fd
,
ppContext
,
refCount
);
return
pContext
;
}
}
...
...
@@ -141,9 +135,10 @@ HttpContext *httpGetContext(void *ptr) {
void
httpReleaseContext
(
HttpContext
*
pContext
)
{
int32_t
refCount
=
atomic_sub_fetch_32
(
&
pContext
->
refCount
,
1
);
assert
(
refCount
>=
0
);
httpDebug
(
"context:%p, is releasd, refCount:%d"
,
pContext
,
refCount
);
HttpContext
**
ppContext
=
pContext
->
ppContext
;
httpDebug
(
"context:%p, is releasd, data:%p refCount:%d"
,
pContext
,
ppContext
,
refCount
);
if
(
tsHttpServer
.
contextCache
!=
NULL
)
{
taosCacheRelease
(
tsHttpServer
.
contextCache
,
(
void
**
)(
&
ppContext
),
false
);
}
else
{
...
...
src/plugins/http/src/httpSession.c
浏览文件 @
d8cfe2d3
...
...
@@ -115,7 +115,7 @@ void httpCleanUpSessions() {
}
bool
httpInitSessions
()
{
tsHttpServer
.
sessionCache
=
taosCacheInitWithCb
(
TSDB_DATA_TYPE_BINARY
,
5
,
false
,
httpDestroySession
);
tsHttpServer
.
sessionCache
=
taosCacheInitWithCb
(
TSDB_DATA_TYPE_BINARY
,
5
,
false
,
httpDestroySession
,
"rests"
);
if
(
tsHttpServer
.
sessionCache
==
NULL
)
{
httpError
(
"failed to init session cache"
);
return
false
;
...
...
src/util/inc/tcache.h
浏览文件 @
d8cfe2d3
...
...
@@ -65,6 +65,7 @@ typedef struct {
int64_t
totalSize
;
// total allocated buffer in this hash table, SCacheObj is not included.
int64_t
refreshTime
;
STrashElem
*
pTrash
;
const
char
*
cacheName
;
// void * tmrCtrl;
// void * pTimer;
SCacheStatis
statistics
;
...
...
@@ -90,7 +91,7 @@ typedef struct {
* @param fn free resource callback function
* @return
*/
SCacheObj
*
taosCacheInit
(
int32_t
keyType
,
int64_t
refreshTimeInSeconds
,
bool
extendLifespan
,
__cache_freeres_fn_t
fn
);
SCacheObj
*
taosCacheInit
(
int32_t
keyType
,
int64_t
refreshTimeInSeconds
,
bool
extendLifespan
,
__cache_freeres_fn_t
fn
,
const
char
*
cacheName
);
/**
* initialize the cache object and set the free object callback function
...
...
@@ -98,7 +99,7 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext
* @param freeCb
* @return
*/
SCacheObj
*
taosCacheInitWithCb
(
int32_t
keyType
,
int64_t
refreshTimeInSeconds
,
bool
extendLifespan
,
__cache_freeres_fn_t
fn
);
SCacheObj
*
taosCacheInitWithCb
(
int32_t
keyType
,
int64_t
refreshTimeInSeconds
,
bool
extendLifespan
,
__cache_freeres_fn_t
fn
,
const
char
*
cacheName
);
/**
* add data into cache
...
...
@@ -128,7 +129,7 @@ void *taosCacheAcquireByKey(SCacheObj *pCacheObj, const void *key, size_t keyLen
* @param expireTime new expire time of data
* @return
*/
void
*
taosCacheUpdateExpireTimeByName
(
SCacheObj
*
pCacheObj
,
const
char
*
key
,
size_t
keyLen
,
uint64_t
expireTime
);
void
*
taosCacheUpdateExpireTimeByName
(
SCacheObj
*
pCacheObj
,
void
*
key
,
size_t
keyLen
,
uint64_t
expireTime
);
/**
* Add one reference count for the exist data, and assign this data for a new owner.
...
...
src/util/src/tcache.c
浏览文件 @
d8cfe2d3
...
...
@@ -119,7 +119,9 @@ static FORCE_INLINE void taosCacheReleaseNode(SCacheObj *pCacheObj, SCacheDataNo
int32_t
size
=
pNode
->
size
;
taosHashRemove
(
pCacheObj
->
pHashTable
,
pNode
->
key
,
pNode
->
keySize
);
uDebug
(
"key:%p, is removed from cache,total:%"
PRId64
",size:%dbytes"
,
pNode
->
key
,
pCacheObj
->
totalSize
,
size
);
uDebug
(
"key:%p, %p is destroyed from cache, totalNum:%d totalSize:%"
PRId64
"bytes size:%dbytes, cacheName:%s"
,
pNode
->
key
,
pNode
->
data
,
(
int32_t
)
taosHashGetSize
(
pCacheObj
->
pHashTable
),
pCacheObj
->
totalSize
,
size
,
pCacheObj
->
cacheName
);
if
(
pCacheObj
->
freeFp
)
pCacheObj
->
freeFp
(
pNode
->
data
);
free
(
pNode
);
}
...
...
@@ -224,7 +226,7 @@ static void doCleanupDataCache(SCacheObj *pCacheObj);
*/
static
void
*
taosCacheRefresh
(
void
*
handle
);
SCacheObj
*
taosCacheInitWithCb
(
int32_t
keyType
,
int64_t
refreshTimeInSeconds
,
bool
extendLifespan
,
__cache_freeres_fn_t
fn
)
{
SCacheObj
*
taosCacheInitWithCb
(
int32_t
keyType
,
int64_t
refreshTimeInSeconds
,
bool
extendLifespan
,
__cache_freeres_fn_t
fn
,
const
char
*
cacheName
)
{
if
(
refreshTimeInSeconds
<=
0
)
{
return
NULL
;
}
...
...
@@ -236,6 +238,7 @@ SCacheObj *taosCacheInitWithCb(int32_t keyType, int64_t refreshTimeInSeconds, bo
}
pCacheObj
->
pHashTable
=
taosHashInit
(
128
,
taosGetDefaultHashFunction
(
keyType
),
false
);
pCacheObj
->
cacheName
=
cacheName
;
if
(
pCacheObj
->
pHashTable
==
NULL
)
{
free
(
pCacheObj
);
uError
(
"failed to allocate memory, reason:%s"
,
strerror
(
errno
));
...
...
@@ -265,8 +268,8 @@ SCacheObj *taosCacheInitWithCb(int32_t keyType, int64_t refreshTimeInSeconds, bo
return
pCacheObj
;
}
SCacheObj
*
taosCacheInit
(
int32_t
keyType
,
int64_t
refreshTimeInSeconds
,
bool
extendLifespan
,
__cache_freeres_fn_t
fn
)
{
return
taosCacheInitWithCb
(
keyType
,
refreshTimeInSeconds
,
extendLifespan
,
fn
);
SCacheObj
*
taosCacheInit
(
int32_t
keyType
,
int64_t
refreshTimeInSeconds
,
bool
extendLifespan
,
__cache_freeres_fn_t
fn
,
const
char
*
cacheName
)
{
return
taosCacheInitWithCb
(
keyType
,
refreshTimeInSeconds
,
extendLifespan
,
fn
,
cacheName
);
}
void
*
taosCachePut
(
SCacheObj
*
pCacheObj
,
const
void
*
key
,
size_t
keyLen
,
const
void
*
pData
,
size_t
dataSize
,
int
duration
)
{
...
...
@@ -285,14 +288,16 @@ void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const v
if
(
NULL
!=
pNode
)
{
pCacheObj
->
totalSize
+=
pNode
->
size
;
uDebug
(
"key:%p, %p added into cache, added:%"
PRIu64
", expire:%"
PRIu64
", total:%"
PRId64
", size:%"
PRId64
" bytes"
,
key
,
pNode
,
pNode
->
addedTime
,
(
pNode
->
lifespan
*
pNode
->
extendFactor
+
pNode
->
addedTime
),
pCacheObj
->
totalSize
,
dataSize
);
uDebug
(
"key:%p, %p added into cache, added:%"
PRIu64
", expire:%"
PRIu64
", totalNum:%d totalSize:%"
PRId64
"bytes size:%"
PRId64
"bytes, cacheName:%s"
,
key
,
pNode
->
data
,
pNode
->
addedTime
,
(
pNode
->
lifespan
*
pNode
->
extendFactor
+
pNode
->
addedTime
),
(
int32_t
)
taosHashGetSize
(
pCacheObj
->
pHashTable
),
pCacheObj
->
totalSize
,
dataSize
,
pCacheObj
->
cacheName
);
}
else
{
uError
(
"key:%p, failed to added into cache, out of memory
"
,
key
);
uError
(
"key:%p, failed to added into cache, out of memory
, cacheName:%s"
,
key
,
pCacheObj
->
cacheName
);
}
}
else
{
// old data exists, update the node
pNode
=
taosUpdateCacheImpl
(
pCacheObj
,
pOld
,
key
,
keyLen
,
pData
,
dataSize
,
duration
*
1000L
);
uDebug
(
"key:%p, %p exist in cache, updated
"
,
key
,
pNod
e
);
uDebug
(
"key:%p, %p exist in cache, updated
, cacheName:%s"
,
key
,
pNode
->
data
,
pCacheObj
->
cacheNam
e
);
}
__cache_unlock
(
pCacheObj
);
...
...
@@ -327,17 +332,17 @@ void *taosCacheAcquireByKey(SCacheObj *pCacheObj, const void *key, size_t keyLen
if
(
ptNode
!=
NULL
)
{
atomic_add_fetch_32
(
&
pCacheObj
->
statistics
.
hitCount
,
1
);
uDebug
(
"key:%p,
is retrieved from cache, %p refcnt:%d"
,
key
,
(
*
ptNode
),
ref
);
uDebug
(
"key:%p,
%p is retrieved from cache, refcnt:%d, cacheName:%s"
,
key
,
(
*
ptNode
)
->
data
,
ref
,
pCacheObj
->
cacheName
);
}
else
{
atomic_add_fetch_32
(
&
pCacheObj
->
statistics
.
missCount
,
1
);
uDebug
(
"key:%p, not in cache, retrieved failed
"
,
key
);
uDebug
(
"key:%p, not in cache, retrieved failed
, cacheName:%s"
,
key
,
pCacheObj
->
cacheName
);
}
atomic_add_fetch_32
(
&
pCacheObj
->
statistics
.
totalAccess
,
1
);
return
(
ptNode
!=
NULL
)
?
(
*
ptNode
)
->
data
:
NULL
;
}
void
*
taosCacheUpdateExpireTimeByName
(
SCacheObj
*
pCacheObj
,
const
char
*
key
,
size_t
keyLen
,
uint64_t
expireTime
)
{
void
*
taosCacheUpdateExpireTimeByName
(
SCacheObj
*
pCacheObj
,
void
*
key
,
size_t
keyLen
,
uint64_t
expireTime
)
{
if
(
pCacheObj
==
NULL
||
taosHashGetSize
(
pCacheObj
->
pHashTable
)
==
0
)
{
return
NULL
;
}
...
...
@@ -355,10 +360,11 @@ void* taosCacheUpdateExpireTimeByName(SCacheObj *pCacheObj, const char *key, siz
if
(
ptNode
!=
NULL
)
{
atomic_add_fetch_32
(
&
pCacheObj
->
statistics
.
hitCount
,
1
);
uDebug
(
"key:%p, expireTime is updated in cache, %p refcnt:%d"
,
key
,
(
*
ptNode
),
T_REF_VAL_GET
(
*
ptNode
));
uDebug
(
"key:%p, %p expireTime is updated in cache, refcnt:%d, cacheName:%s"
,
key
,
(
*
ptNode
)
->
data
,
T_REF_VAL_GET
(
*
ptNode
),
pCacheObj
->
cacheName
);
}
else
{
atomic_add_fetch_32
(
&
pCacheObj
->
statistics
.
missCount
,
1
);
uDebug
(
"key:%p, not in cache, retrieved failed
"
,
key
);
uDebug
(
"key:%p, not in cache, retrieved failed
, cacheName:%s"
,
key
,
pCacheObj
->
cacheName
);
}
atomic_add_fetch_32
(
&
pCacheObj
->
statistics
.
totalAccess
,
1
);
...
...
@@ -377,7 +383,7 @@ void *taosCacheAcquireByData(SCacheObj *pCacheObj, void *data) {
}
int32_t
ref
=
T_REF_INC
(
ptNode
);
uDebug
(
"%p acquired by data in cache, refcnt:%d
"
,
ptNode
,
ref
)
uDebug
(
"%p acquired by data in cache, refcnt:%d
, cacheName:%s"
,
ptNode
->
data
,
ref
,
pCacheObj
->
cacheName
);
// if the remained life span is less then the (*ptNode)->lifeSpan, add up one lifespan
if
(
pCacheObj
->
extendLifespan
)
{
...
...
@@ -385,7 +391,8 @@ void *taosCacheAcquireByData(SCacheObj *pCacheObj, void *data) {
if
((
now
-
ptNode
->
addedTime
)
<
ptNode
->
lifespan
*
ptNode
->
extendFactor
)
{
ptNode
->
extendFactor
+=
1
;
uDebug
(
"key:%p extend life time to %"
PRId64
,
ptNode
,
ptNode
->
lifespan
*
ptNode
->
extendFactor
+
ptNode
->
addedTime
);
uDebug
(
"%p extend life time to %"
PRId64
,
ptNode
->
data
,
ptNode
->
lifespan
*
ptNode
->
extendFactor
+
ptNode
->
addedTime
);
}
}
...
...
@@ -424,13 +431,13 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) {
SCacheDataNode
*
pNode
=
(
SCacheDataNode
*
)((
char
*
)(
*
data
)
-
offset
);
if
(
pNode
->
signature
!=
(
uint64_t
)
pNode
)
{
uError
(
"
key:
%p, release invalid cache data"
,
pNode
);
uError
(
"%p, release invalid cache data"
,
pNode
);
return
;
}
*
data
=
NULL
;
int16_t
ref
=
T_REF_DEC
(
pNode
);
uDebug
(
"
%p data released, refcnt:%d"
,
pNode
,
ref
);
uDebug
(
"
key:%p, %p is released, refcnt:%d, cacheName:%s"
,
pNode
->
key
,
pNode
->
data
,
ref
,
pCacheObj
->
cacheName
);
if
(
_remove
&&
(
!
pNode
->
inTrashCan
))
{
__cache_wr_lock
(
pCacheObj
);
...
...
@@ -474,6 +481,7 @@ void taosCacheCleanup(SCacheObj *pCacheObj) {
pCacheObj
->
deleting
=
1
;
pthread_join
(
pCacheObj
->
refreshWorker
,
NULL
);
uInfo
(
"cacheName:%p, will be cleanuped"
,
pCacheObj
->
cacheName
);
doCleanupDataCache
(
pCacheObj
);
}
...
...
@@ -522,7 +530,7 @@ void taosAddToTrash(SCacheObj *pCacheObj, SCacheDataNode *pNode) {
pNode
->
inTrashCan
=
true
;
pCacheObj
->
numOfElemsInTrash
++
;
uDebug
(
"key:%p, %p move to trash, numOfElem in trash:%d"
,
pNode
->
key
,
pNode
,
pCacheObj
->
numOfElemsInTrash
);
uDebug
(
"key:%p, %p move to trash, numOfElem in trash:%d"
,
pNode
->
key
,
pNode
->
data
,
pCacheObj
->
numOfElemsInTrash
);
}
void
taosRemoveFromTrashCan
(
SCacheObj
*
pCacheObj
,
STrashElem
*
pElem
)
{
...
...
@@ -573,7 +581,7 @@ void taosTrashCanEmpty(SCacheObj *pCacheObj, bool force) {
}
if
(
force
||
(
T_REF_VAL_GET
(
pElem
->
pData
)
==
0
))
{
uDebug
(
"key:%p, %p removed from trash. numOfElem in trash:%d"
,
pElem
->
pData
->
key
,
pElem
->
pData
,
uDebug
(
"key:%p, %p removed from trash. numOfElem in trash:%d"
,
pElem
->
pData
->
key
,
pElem
->
pData
->
data
,
pCacheObj
->
numOfElemsInTrash
-
1
);
STrashElem
*
p
=
pElem
;
...
...
@@ -597,7 +605,8 @@ void doCleanupDataCache(SCacheObj *pCacheObj) {
if
(
T_REF_VAL_GET
(
pNode
)
<=
0
)
{
taosCacheReleaseNode
(
pCacheObj
,
pNode
);
}
else
{
uDebug
(
"key:%p, will not remove from cache, refcnt:%d"
,
pNode
->
key
,
T_REF_VAL_GET
(
pNode
));
uDebug
(
"key:%p, %p will not remove from cache, refcnt:%d, cacheName:%s"
,
pNode
->
key
,
pNode
->
data
,
T_REF_VAL_GET
(
pNode
),
pCacheObj
->
cacheName
);
}
}
taosHashDestroyIter
(
pIter
);
...
...
src/util/tests/cacheTest.cpp
浏览文件 @
d8cfe2d3
...
...
@@ -19,7 +19,7 @@ int32_t tsMaxMeterConnections = 200;
// test cache
TEST
(
testCase
,
client_cache_test
)
{
const
int32_t
REFRESH_TIME_IN_SEC
=
2
;
SCacheObj
*
tscCacheHandle
=
taosCacheInit
(
TSDB_DATA_TYPE_BINARY
,
REFRESH_TIME_IN_SEC
,
0
,
NULL
);
SCacheObj
*
tscCacheHandle
=
taosCacheInit
(
TSDB_DATA_TYPE_BINARY
,
REFRESH_TIME_IN_SEC
,
0
,
NULL
,
"test"
);
const
char
*
key1
=
"test1"
;
char
data1
[]
=
"test11"
;
...
...
@@ -105,7 +105,7 @@ TEST(testCase, client_cache_test) {
TEST
(
testCase
,
cache_resize_test
)
{
const
int32_t
REFRESH_TIME_IN_SEC
=
2
;
auto
*
pCache
=
taosCacheInit
(
TSDB_DATA_TYPE_BINARY
,
REFRESH_TIME_IN_SEC
,
false
,
NULL
);
auto
*
pCache
=
taosCacheInit
(
TSDB_DATA_TYPE_BINARY
,
REFRESH_TIME_IN_SEC
,
false
,
NULL
,
"test"
);
char
key
[
256
]
=
{
0
};
char
data
[
1024
]
=
"abcdefghijk"
;
...
...
src/vnode/src/vnodeMain.c
浏览文件 @
d8cfe2d3
...
...
@@ -284,7 +284,7 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
cqStart
(
pVnode
->
cq
);
const
int32_t
REFRESH_HANDLE_INTERVAL
=
2
;
// every 2 seconds, rfresh handle pool
pVnode
->
qHandlePool
=
taosCacheInit
(
TSDB_DATA_TYPE_BIGINT
,
REFRESH_HANDLE_INTERVAL
,
true
,
vnodeFreeqHandle
);
pVnode
->
qHandlePool
=
taosCacheInit
(
TSDB_DATA_TYPE_BIGINT
,
REFRESH_HANDLE_INTERVAL
,
true
,
vnodeFreeqHandle
,
"qhandle"
);
pVnode
->
events
=
NULL
;
pVnode
->
status
=
TAOS_VN_STATUS_READY
;
...
...
tests/script/sh/deploy.sh
浏览文件 @
d8cfe2d3
...
...
@@ -114,10 +114,11 @@ echo "mDebugFlag 135" >> $TAOS_CFG
echo
"sdbDebugFlag 135"
>>
$TAOS_CFG
echo
"dDebugFlag 135"
>>
$TAOS_CFG
echo
"vDebugFlag 135"
>>
$TAOS_CFG
echo
"tsdbDebugFlag 135"
>>
$TAOS_CFG
echo
"cDebugFlag 135"
>>
$TAOS_CFG
echo
"jnidebugFlag 135"
>>
$TAOS_CFG
echo
"odbcdebugFlag 135"
>>
$TAOS_CFG
echo
"httpDebugFlag 1
43
"
>>
$TAOS_CFG
echo
"httpDebugFlag 1
35
"
>>
$TAOS_CFG
echo
"monitorDebugFlag 131"
>>
$TAOS_CFG
echo
"mqttDebugFlag 131"
>>
$TAOS_CFG
echo
"qdebugFlag 135"
>>
$TAOS_CFG
...
...
@@ -132,7 +133,7 @@ echo "monitorInterval 1" >> $TAOS_CFG
echo
"http 0"
>>
$TAOS_CFG
echo
"numOfThreadsPerCore 2.0"
>>
$TAOS_CFG
echo
"defaultPass taosdata"
>>
$TAOS_CFG
echo
"numOfLogLines 10000000
0
"
>>
$TAOS_CFG
echo
"numOfLogLines 10000000"
>>
$TAOS_CFG
echo
"mnodeEqualVnodeNum 0"
>>
$TAOS_CFG
echo
"clog 2"
>>
$TAOS_CFG
echo
"statusInterval 1"
>>
$TAOS_CFG
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录