From 49944faf7d8aff8936817c20104494742532d8d2 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 11 Aug 2020 09:47:23 +0800 Subject: [PATCH 1/4] TD-1081 change httpContext keep time --- src/mnode/src/mnodeProfile.c | 4 ++-- src/mnode/src/mnodeShow.c | 2 +- src/plugins/http/src/httpContext.c | 2 +- src/plugins/http/src/httpSession.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mnode/src/mnodeProfile.c b/src/mnode/src/mnodeProfile.c index 85457d7a26..01a824baa7 100644 --- a/src/mnode/src/mnodeProfile.c +++ b/src/mnode/src/mnodeProfile.c @@ -35,8 +35,8 @@ #include "mnodeVgroup.h" #include "mnodeWrite.h" -#define CONN_KEEP_TIME (tsShellActivityTimer * 3) -#define CONN_CHECK_TIME (tsShellActivityTimer * 2) +#define CONN_KEEP_TIME (tsShellActivityTimer * 3000) +#define CONN_CHECK_TIME (tsShellActivityTimer * 2000) #define QUERY_ID_SIZE 20 #define QUERY_STREAM_SAVE_SIZE 20 diff --git a/src/mnode/src/mnodeShow.c b/src/mnode/src/mnodeShow.c index 9983c111f6..aec946722f 100644 --- a/src/mnode/src/mnodeShow.c +++ b/src/mnode/src/mnodeShow.c @@ -389,7 +389,7 @@ static bool mnodeAccquireShowObj(SShowObj *pShow) { static void* mnodePutShowObj(SShowObj *pShow) { if (tsMnodeShowCache != NULL) { pShow->index = atomic_add_fetch_32(&tsShowObjIndex, 1); - SShowObj **ppShow = taosCachePut(tsMnodeShowCache, &pShow, sizeof(int64_t), &pShow, sizeof(int64_t), 6); + SShowObj **ppShow = taosCachePut(tsMnodeShowCache, &pShow, sizeof(int64_t), &pShow, sizeof(int64_t), 6000); pShow->ppShow = (void**)ppShow; mDebug("%p, show is put into cache, data:%p index:%d", pShow, ppShow, pShow->index); return pShow; diff --git a/src/plugins/http/src/httpContext.c b/src/plugins/http/src/httpContext.c index ad0d302c82..38b829e406 100644 --- a/src/plugins/http/src/httpContext.c +++ b/src/plugins/http/src/httpContext.c @@ -108,7 +108,7 @@ HttpContext *httpCreateContext(int32_t fd) { pContext->lastAccessTime = taosGetTimestampSec(); pContext->state = HTTP_CONTEXT_STATE_READY; - HttpContext **ppContext = taosCachePut(tsHttpServer.contextCache, &pContext, sizeof(int64_t), &pContext, sizeof(int64_t), 3); + HttpContext **ppContext = taosCachePut(tsHttpServer.contextCache, &pContext, sizeof(int64_t), &pContext, sizeof(int64_t), 3000); pContext->ppContext = ppContext; httpDebug("context:%p, fd:%d, is created, data:%p", pContext, fd, ppContext); diff --git a/src/plugins/http/src/httpSession.c b/src/plugins/http/src/httpSession.c index ad57f0fc29..f19679e072 100644 --- a/src/plugins/http/src/httpSession.c +++ b/src/plugins/http/src/httpSession.c @@ -34,7 +34,7 @@ void httpCreateSession(HttpContext *pContext, void *taos) { session.refCount = 1; int32_t len = snprintf(session.id, HTTP_SESSION_ID_LEN, "%s.%s", pContext->user, pContext->pass); - pContext->session = taosCachePut(server->sessionCache, session.id, len, &session, sizeof(HttpSession), tsHttpSessionExpire); + pContext->session = taosCachePut(server->sessionCache, session.id, len, &session, sizeof(HttpSession), tsHttpSessionExpire * 1000); // void *temp = pContext->session; // taosCacheRelease(server->sessionCache, (void **)&temp, false); From 88171545f8e78fdb6e49110297634d5524df94f0 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 11 Aug 2020 03:58:41 +0000 Subject: [PATCH 2/4] TD-1081 change cache key --- src/mnode/src/mnodeShow.c | 6 ++++-- src/plugins/http/src/httpContext.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/mnode/src/mnodeShow.c b/src/mnode/src/mnodeShow.c index aec946722f..8a84b66a33 100644 --- a/src/mnode/src/mnodeShow.c +++ b/src/mnode/src/mnodeShow.c @@ -377,7 +377,8 @@ static bool mnodeCheckShowFinished(SShowObj *pShow) { } static bool mnodeAccquireShowObj(SShowObj *pShow) { - SShowObj **ppShow = taosCacheAcquireByKey(tsMnodeShowCache, &pShow, sizeof(int64_t)); + uint64_t handleVal = (uint64_t)pShow; + SShowObj **ppShow = taosCacheAcquireByKey(tsMnodeShowCache, &handleVal, sizeof(int64_t)); if (ppShow) { mDebug("%p, show is accquired from cache, data:%p, index:%d", pShow, ppShow, pShow->index); return true; @@ -389,7 +390,8 @@ static bool mnodeAccquireShowObj(SShowObj *pShow) { static void* mnodePutShowObj(SShowObj *pShow) { if (tsMnodeShowCache != NULL) { pShow->index = atomic_add_fetch_32(&tsShowObjIndex, 1); - SShowObj **ppShow = taosCachePut(tsMnodeShowCache, &pShow, sizeof(int64_t), &pShow, sizeof(int64_t), 6000); + uint64_t handleVal = (uint64_t)pShow; + SShowObj **ppShow = taosCachePut(tsMnodeShowCache, &handleVal, sizeof(int64_t), &pShow, sizeof(int64_t), 6000); pShow->ppShow = (void**)ppShow; mDebug("%p, show is put into cache, data:%p index:%d", pShow, ppShow, pShow->index); return pShow; diff --git a/src/plugins/http/src/httpContext.c b/src/plugins/http/src/httpContext.c index 38b829e406..5ef3c9a66e 100644 --- a/src/plugins/http/src/httpContext.c +++ b/src/plugins/http/src/httpContext.c @@ -108,7 +108,8 @@ HttpContext *httpCreateContext(int32_t fd) { pContext->lastAccessTime = taosGetTimestampSec(); pContext->state = HTTP_CONTEXT_STATE_READY; - HttpContext **ppContext = taosCachePut(tsHttpServer.contextCache, &pContext, sizeof(int64_t), &pContext, sizeof(int64_t), 3000); + uint64_t handleVal = (uint64_t)pContext; + HttpContext **ppContext = taosCachePut(tsHttpServer.contextCache, &handleVal, sizeof(int64_t), &pContext, sizeof(int64_t), 3000); pContext->ppContext = ppContext; httpDebug("context:%p, fd:%d, is created, data:%p", pContext, fd, ppContext); @@ -119,7 +120,8 @@ HttpContext *httpCreateContext(int32_t fd) { } HttpContext *httpGetContext(void *ptr) { - HttpContext **ppContext = taosCacheAcquireByKey(tsHttpServer.contextCache, &ptr, sizeof(HttpContext *)); + uint64_t handleVal = (uint64_t)ptr; + HttpContext **ppContext = taosCacheAcquireByKey(tsHttpServer.contextCache, &handleVal, sizeof(HttpContext *)); if (ppContext) { HttpContext *pContext = *ppContext; From fe834cc75dce1b55179e69e23ea3e33641f8a193 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 11 Aug 2020 04:43:57 +0000 Subject: [PATCH 3/4] only drop one vnode each time --- src/balance/src/balance.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/balance/src/balance.c b/src/balance/src/balance.c index 53ed860aa1..1c25c04717 100644 --- a/src/balance/src/balance.c +++ b/src/balance/src/balance.c @@ -214,8 +214,8 @@ static bool balanceCheckVgroupReady(SVgObj *pVgroup, SVnodeGid *pRmVnode) { * desc: remove one vnode from vgroup * all vnodes in vgroup should in ready state, except the balancing one **/ -static void balanceRemoveVnode(SVgObj *pVgroup) { - if (pVgroup->numOfVnodes <= 1) return; +static int32_t balanceRemoveVnode(SVgObj *pVgroup) { + if (pVgroup->numOfVnodes <= 1) return -1; SVnodeGid *pRmVnode = NULL; SVnodeGid *pSelVnode = NULL; @@ -258,9 +258,11 @@ static void balanceRemoveVnode(SVgObj *pVgroup) { if (!balanceCheckVgroupReady(pVgroup, pSelVnode)) { mDebug("vgId:%d, is not ready", pVgroup->vgId); + return -1; } else { mDebug("vgId:%d, is ready, discard dnode:%d", pVgroup->vgId, pSelVnode->dnodeId); balanceDiscardVnode(pVgroup, pSelVnode); + return TSDB_CODE_SUCCESS; } } @@ -407,22 +409,22 @@ static int32_t balanceMonitorVgroups() { int32_t dbReplica = pVgroup->pDb->cfg.replications; int32_t vgReplica = pVgroup->numOfVnodes; + int32_t code; if (vgReplica > dbReplica) { mInfo("vgId:%d, replica:%d numOfVnodes:%d, try remove one vnode", pVgroup->vgId, dbReplica, vgReplica); hasUpdatingVgroup = true; - balanceRemoveVnode(pVgroup); + code = balanceRemoveVnode(pVgroup); } else if (vgReplica < dbReplica) { mInfo("vgId:%d, replica:%d numOfVnodes:%d, try add one vnode", pVgroup->vgId, dbReplica, vgReplica); hasUpdatingVgroup = true; - int32_t code = balanceAddVnode(pVgroup, NULL, NULL); - if (code == TSDB_CODE_SUCCESS) { - mnodeDecVgroupRef(pVgroup); - break; - } + code = balanceAddVnode(pVgroup, NULL, NULL); } mnodeDecVgroupRef(pVgroup); + if (code == TSDB_CODE_SUCCESS) { + break; + } } sdbFreeIter(pIter); From 3b8b8414f3ba26f998d07678d7ad024587d853da Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 11 Aug 2020 04:52:44 +0000 Subject: [PATCH 4/4] minor changes --- src/balance/src/balance.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/balance/src/balance.c b/src/balance/src/balance.c index 1c25c04717..53638f1025 100644 --- a/src/balance/src/balance.c +++ b/src/balance/src/balance.c @@ -409,7 +409,7 @@ static int32_t balanceMonitorVgroups() { int32_t dbReplica = pVgroup->pDb->cfg.replications; int32_t vgReplica = pVgroup->numOfVnodes; - int32_t code; + int32_t code = -1; if (vgReplica > dbReplica) { mInfo("vgId:%d, replica:%d numOfVnodes:%d, try remove one vnode", pVgroup->vgId, dbReplica, vgReplica);