diff options
author | Costa Tsaousis <costa@netdata.cloud> | 2023-07-25 18:01:34 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-25 18:01:34 +0300 |
commit | 2d23be7b8fff7bc56e431398cf028025edfa7099 (patch) | |
tree | b2da80ce2671196936c4fd616792032b344db442 /database | |
parent | 4ad42d54e4046cdadc3341d35e59de25bf802513 (diff) |
wait for node_id while claiming (#15526)
Diffstat (limited to 'database')
-rw-r--r-- | database/sqlite/sqlite_functions.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/database/sqlite/sqlite_functions.c b/database/sqlite/sqlite_functions.c index d7c2809915..af7f8147f5 100644 --- a/database/sqlite/sqlite_functions.c +++ b/database/sqlite/sqlite_functions.c @@ -593,15 +593,20 @@ static inline void set_host_node_id(RRDHOST *host, uuid_t *node_id) if (unlikely(!node_id)) { freez(host->node_id); - host->node_id = NULL; + __atomic_store_n(&host->node_id, NULL, __ATOMIC_RELAXED); return; } struct aclk_sync_host_config *wc = host->aclk_sync_host_config; - if (unlikely(!host->node_id)) - host->node_id = mallocz(sizeof(*host->node_id)); - uuid_copy(*(host->node_id), *node_id); + if (unlikely(!host->node_id)) { + uuid_t *t = mallocz(sizeof(*host->node_id)); + uuid_copy(*t, *node_id); + __atomic_store_n(&host->node_id, t, __ATOMIC_RELAXED); + } + else { + uuid_copy(*(host->node_id), *node_id); + } if (unlikely(!wc)) sql_create_aclk_table(host, &host->host_uuid, node_id); @@ -617,6 +622,14 @@ int update_node_id(uuid_t *host_id, uuid_t *node_id) RRDHOST *host = NULL; int rc = 2; + char host_guid[GUID_LEN + 1]; + uuid_unparse_lower(*host_id, host_guid); + rrd_wrlock(); + host = rrdhost_find_by_guid(host_guid); + if (likely(host)) + set_host_node_id(host, node_id); + rrd_unlock(); + if (unlikely(!db_meta)) { if (default_rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) error_report("Database has not been initialized"); @@ -646,14 +659,6 @@ int update_node_id(uuid_t *host_id, uuid_t *node_id) error_report("Failed to store node instance information, rc = %d", rc); rc = sqlite3_changes(db_meta); - char host_guid[GUID_LEN + 1]; - uuid_unparse_lower(*host_id, host_guid); - rrd_wrlock(); - host = rrdhost_find_by_guid(host_guid); - if (likely(host)) - set_host_node_id(host, node_id); - rrd_unlock(); - failed: if (unlikely(sqlite3_finalize(res) != SQLITE_OK)) error_report("Failed to finalize the prepared statement when storing node instance information"); |