From 4c401c39fbf4ca9bd85a0d0dc0e56c840c6089d7 Mon Sep 17 00:00:00 2001 From: dmchen Date: Tue, 24 Oct 2023 09:52:34 +0000 Subject: [PATCH] atomic --- source/dnode/mgmt/node_mgmt/src/dmMonitor.c | 12 ++++++------ source/libs/monitorfw/inc/taos_metric_sample_t.h | 2 +- source/libs/monitorfw/src/taos_collector.c | 1 - source/libs/monitorfw/src/taos_metric_formatter.c | 2 +- source/libs/monitorfw/src/taos_metric_sample.c | 13 +++++++++++++ 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/source/dnode/mgmt/node_mgmt/src/dmMonitor.c b/source/dnode/mgmt/node_mgmt/src/dmMonitor.c index bf88d0014e..02d8bb43ea 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmMonitor.c +++ b/source/dnode/mgmt/node_mgmt/src/dmMonitor.c @@ -99,12 +99,12 @@ void dmSendMonitorReport() { if (!tsEnableMonitor || tsMonitorFqdn[0] == 0 || tsMonitorPort == 0) return; dTrace("send monitor report to %s:%u", tsMonitorFqdn, tsMonitorPort); - SDnode *pDnode = dmInstance(); - dmGetDmMonitorInfo(pDnode); - dmGetMmMonitorInfo(pDnode); - dmGetVmMonitorInfo(pDnode); - dmGetQmMonitorInfo(pDnode); - dmGetSmMonitorInfo(pDnode); + //SDnode *pDnode = dmInstance(); + //dmGetDmMonitorInfo(pDnode); + //dmGetMmMonitorInfo(pDnode); + //dmGetVmMonitorInfo(pDnode); + //dmGetQmMonitorInfo(pDnode); + //dmGetSmMonitorInfo(pDnode); //monSendReport(); monSendPromReport(); diff --git a/source/libs/monitorfw/inc/taos_metric_sample_t.h b/source/libs/monitorfw/inc/taos_metric_sample_t.h index 59a398b938..92885acf4a 100644 --- a/source/libs/monitorfw/inc/taos_metric_sample_t.h +++ b/source/libs/monitorfw/inc/taos_metric_sample_t.h @@ -22,7 +22,7 @@ struct taos_metric_sample { taos_metric_type_t type; /**< type is the metric type for the sample */ char *l_value; /**< l_value is the full metric name and label set represeted as a string */ - _Atomic double r_value; /**< r_value is the value of the metric sample */ + /*_Atomic*/ int64_t r_value; /**< r_value is the value of the metric sample */ }; #endif // TAOS_METRIC_SAMPLE_T_H diff --git a/source/libs/monitorfw/src/taos_collector.c b/source/libs/monitorfw/src/taos_collector.c index 9d96f61b4b..d3228facb6 100644 --- a/source/libs/monitorfw/src/taos_collector.c +++ b/source/libs/monitorfw/src/taos_collector.c @@ -14,7 +14,6 @@ */ #include -#include // Public #include "taos_alloc.h" diff --git a/source/libs/monitorfw/src/taos_metric_formatter.c b/source/libs/monitorfw/src/taos_metric_formatter.c index 3529d9dda6..77361b8b03 100644 --- a/source/libs/monitorfw/src/taos_metric_formatter.c +++ b/source/libs/monitorfw/src/taos_metric_formatter.c @@ -171,7 +171,7 @@ int taos_metric_formatter_load_sample(taos_metric_formatter_t *self, taos_metric if (r) return r; char buffer[50]; - sprintf(buffer, "%.17g", sample->r_value); + sprintf(buffer, "%ld", sample->r_value); r = taos_string_builder_add_str(self->string_builder, buffer); if (r) return r; diff --git a/source/libs/monitorfw/src/taos_metric_sample.c b/source/libs/monitorfw/src/taos_metric_sample.c index 747eebc87c..10f626ba16 100644 --- a/source/libs/monitorfw/src/taos_metric_sample.c +++ b/source/libs/monitorfw/src/taos_metric_sample.c @@ -24,6 +24,7 @@ #include "taos_log.h" #include "taos_metric_sample_i.h" #include "taos_metric_sample_t.h" +#include "osAtomic.h" taos_metric_sample_t *taos_metric_sample_new(taos_metric_type_t type, const char *l_value, double r_value) { taos_metric_sample_t *self = (taos_metric_sample_t *)taos_malloc(sizeof(taos_metric_sample_t)); @@ -62,13 +63,18 @@ int taos_metric_sample_add(taos_metric_sample_t *self, double r_value) { if (r_value < 0) { return 1; } + /* _Atomic double old = atomic_load(&self->r_value); + for (;;) { _Atomic double new = ATOMIC_VAR_INIT(old + r_value); if (atomic_compare_exchange_weak(&self->r_value, &old, new)) { return 0; } } + */ + atomic_fetch_add_64(&self->r_value, r_value); + return 0; } int taos_metric_sample_sub(taos_metric_sample_t *self, double r_value) { @@ -77,6 +83,7 @@ int taos_metric_sample_sub(taos_metric_sample_t *self, double r_value) { TAOS_LOG(TAOS_METRIC_INCORRECT_TYPE); return 1; } + /* _Atomic double old = atomic_load(&self->r_value); for (;;) { _Atomic double new = ATOMIC_VAR_INIT(old - r_value); @@ -84,6 +91,9 @@ int taos_metric_sample_sub(taos_metric_sample_t *self, double r_value) { return 0; } } + */ + atomic_fetch_sub_64(&self->r_value, r_value); + return 0; } int taos_metric_sample_set(taos_metric_sample_t *self, double r_value) { @@ -91,6 +101,9 @@ int taos_metric_sample_set(taos_metric_sample_t *self, double r_value) { TAOS_LOG(TAOS_METRIC_INCORRECT_TYPE); return 1; } + /* atomic_store(&self->r_value, r_value); + */ + atomic_store_64(&self->r_value, r_value); return 0; }