From 97bcdfb86c27c2f7e536079b8d57f64f0aa8620a Mon Sep 17 00:00:00 2001 From: xiao77 Date: Tue, 3 Sep 2024 20:09:06 +0800 Subject: [PATCH] resolve comments --- include/libs/monitorfw/taos_counter.h | 2 +- source/dnode/mgmt/mgmt_vnode/src/vmHandle.c | 20 ++++++++++++++------ source/dnode/mgmt/node_mgmt/inc/dmNodes.h | 2 +- source/dnode/mgmt/node_mgmt/src/dmMonitor.c | 13 +++++++------ source/libs/monitorfw/src/taos_counter.c | 11 +++++++---- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/include/libs/monitorfw/taos_counter.h b/include/libs/monitorfw/taos_counter.h index 816d8ea7b9..910f6e1aed 100644 --- a/include/libs/monitorfw/taos_counter.h +++ b/include/libs/monitorfw/taos_counter.h @@ -99,7 +99,7 @@ int taos_counter_inc(taos_counter_t *self, const char **label_values); */ int taos_counter_add(taos_counter_t *self, double r_value, const char **label_values); -int taos_counter_get_vgroup_ids(taos_counter_t *self, char ***keys, int32_t **vgroup_ids); +int taos_counter_get_vgroup_ids(taos_counter_t *self, char ***keys, int32_t **vgroup_ids, int *list_size); int taos_counter_get_keys_size(taos_counter_t *self); int taos_counter_delete(taos_counter_t *self, char *key); #endif // TAOS_COUNTER_H diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 8ec51b637b..cf0f38243e 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -120,25 +120,33 @@ void vmGetMonitorInfo(SVnodeMgmt *pMgmt, SMonVmInfo *pInfo) { taosArrayDestroy(pVloads); } -int vmCleanExpriedSamples(SVnodeMgmt *pMgmt) { +void vmCleanExpriedSamples(SVnodeMgmt *pMgmt) { int list_size = taos_counter_get_keys_size(tsInsertCounter); - if (list_size == 0) return 0; + if (list_size == 0) return; int32_t *vgroup_ids; char **keys; - taos_counter_get_vgroup_ids(tsInsertCounter, &keys, &vgroup_ids); - int r = 0; - (void)taosThreadRwlockWrlock(&pMgmt->lock); + int r = 0; + r = taos_counter_get_vgroup_ids(tsInsertCounter, &keys, &vgroup_ids, &list_size); + if (r) { + dError("failed to get vgroup ids"); + return; + } + (void)taosThreadRwlockRdlock(&pMgmt->lock); for (int i = 0; i < list_size; i++) { int32_t vgroup_id = vgroup_ids[i]; void *vnode = taosHashGet(pMgmt->hash, &vgroup_id, sizeof(int32_t)); if (vnode == NULL) { r = taos_counter_delete(tsInsertCounter, keys[i]); + if (r) { + dError("failed to delete key:%s", keys[i]); + return; + } } } (void)taosThreadRwlockUnlock(&pMgmt->lock); taosMemoryFree(vgroup_ids); taosMemoryFree(keys); - return r; + return; } static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) { diff --git a/source/dnode/mgmt/node_mgmt/inc/dmNodes.h b/source/dnode/mgmt/node_mgmt/inc/dmNodes.h index c0ef92b537..2561a13b92 100644 --- a/source/dnode/mgmt/node_mgmt/inc/dmNodes.h +++ b/source/dnode/mgmt/node_mgmt/inc/dmNodes.h @@ -39,7 +39,7 @@ void vmGetVnodeLoadsLite(void *pMgmt, SMonVloadInfo *pInfo); void mmGetMnodeLoads(void *pMgmt, SMonMloadInfo *pInfo); void qmGetQnodeLoads(void *pMgmt, SQnodeLoad *pInfo); -int vmCleanExpriedSamples(void *pMgmt); +void vmCleanExpriedSamples(void *pMgmt); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/node_mgmt/src/dmMonitor.c b/source/dnode/mgmt/node_mgmt/src/dmMonitor.c index 61cdd5a272..68a851569c 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmMonitor.c +++ b/source/dnode/mgmt/node_mgmt/src/dmMonitor.c @@ -14,9 +14,9 @@ */ #define _DEFAULT_SOURCE -#include "audit.h" #include "dmMgmt.h" #include "dmNodes.h" +#include "audit.h" static void dmGetMonitorBasicInfo(SDnode *pDnode, SMonBasicInfo *pInfo) { pInfo->protocol = 1; @@ -52,14 +52,15 @@ static void dmGetDmMonitorInfo(SDnode *pDnode) { monSetDmInfo(&dmInfo); } -int dmCleanExpriedSamples(SDnode *pDnode) { +void dmCleanExpriedSamples(SDnode *pDnode) { SMgmtWrapper *pWrapper = &pDnode->wrappers[VNODE]; if (dmMarkWrapper(pWrapper) == 0) { if (pWrapper->pMgmt != NULL) { - return vmCleanExpriedSamples(pWrapper->pMgmt); + vmCleanExpriedSamples(pWrapper->pMgmt); } } - return 0; + dmReleaseWrapper(pWrapper); + return; } static void dmGetDmMonitorInfoBasic(SDnode *pDnode) { @@ -134,8 +135,8 @@ void dmSendMonitorReport() { } void dmMonitorCleanExpiredSamples() { - if (!tsEnableMonitor || tsMonitorFqdn[0] == 0 || tsMonitorPort == 0) return; - dTrace("send monitor report to %s:%u", tsMonitorFqdn, tsMonitorPort); + if (!tsEnableMonitor) return; + dTrace("clean monitor expired samples"); SDnode *pDnode = dmInstance(); (void)dmCleanExpriedSamples(pDnode); diff --git a/source/libs/monitorfw/src/taos_counter.c b/source/libs/monitorfw/src/taos_counter.c index 84e29b5f93..829a05aa4e 100644 --- a/source/libs/monitorfw/src/taos_counter.c +++ b/source/libs/monitorfw/src/taos_counter.c @@ -68,7 +68,7 @@ int taos_counter_add(taos_counter_t *self, double r_value, const char **label_va int taos_counter_get_keys_size(taos_counter_t *self) { return self->samples->keys->size; } -int taos_counter_get_vgroup_ids(taos_counter_t *self, char ***keys, int32_t **vgroup_ids) { +int taos_counter_get_vgroup_ids(taos_counter_t *self, char ***keys, int32_t **vgroup_ids, int *list_size) { TAOS_TEST_PARA(self != NULL); if (self == NULL) return 1; if (self->type != TAOS_COUNTER) { @@ -77,9 +77,12 @@ int taos_counter_get_vgroup_ids(taos_counter_t *self, char ***keys, int32_t **vg } if (self->samples == NULL) return 1; taos_linked_list_t *key_list = self->samples->keys; - int r = 0; - *vgroup_ids = (int32_t *)taos_malloc(key_list->size * sizeof(int32_t)); - *keys = (char **)taos_malloc(key_list->size * sizeof(char *)); + *list_size = key_list->size; + int r = 0; + *vgroup_ids = (int32_t *)taos_malloc(*list_size * sizeof(int32_t)); + if (vgroup_ids == NULL) return 1; + *keys = (char **)taos_malloc(*list_size * sizeof(char *)); + if (keys == NULL) return 1; int index = 0; for (taos_linked_list_node_t *current_key = key_list->head; current_key != NULL; current_key = current_key->next) { char *key = (char *)current_key->item;