wait for node_id while claiming (#15526)
Costa Tsaousis committed
Jul 25, 2023 at 18:01 UTC
2d23be7b8fff7bc56e431398cf028025edfa7099
2 files changed
+21
-16
claim/claim.c
+4
-4
@@ -409,12 +409,12 @@ int api_v2_claim(struct web_client *w, char *url) {
409
int ms = 0;
410
do {
411
status = cloud_status();
412
- if (status == CLOUD_STATUS_ONLINE)
412
+ if (status == CLOUD_STATUS_ONLINE && __atomic_load_n(&localhost->node_id, __ATOMIC_RELAXED))
413
break;
414
415
- sleep_usec(100 * USEC_PER_MS);
416
- ms += 100;
417
- } while (ms < 5000);
415
+ sleep_usec(50 * USEC_PER_MS);
416
+ ms += 50;
417
+ } while (ms < 10000);
418
}
419
break;
420
database/sqlite/sqlite_functions.c
+17
-12
@@ -593,15 +593,20 @@ static inline void set_host_node_id(RRDHOST *host, uuid_t *node_id)
593
594
if (unlikely(!node_id)) {
595
freez(host->node_id);
596
- host->node_id = NULL;
596
+ __atomic_store_n(&host->node_id, NULL, __ATOMIC_RELAXED);
597
return;
598
}
599
600
struct aclk_sync_host_config *wc = host->aclk_sync_host_config;
601
602
- if (unlikely(!host->node_id))
603
- host->node_id = mallocz(sizeof(*host->node_id));
604
- uuid_copy(*(host->node_id), *node_id);
602
+ if (unlikely(!host->node_id)) {
603
+ uuid_t *t = mallocz(sizeof(*host->node_id));
604
+ uuid_copy(*t, *node_id);
605
+ __atomic_store_n(&host->node_id, t, __ATOMIC_RELAXED);
606
+ }
607
+ else {
608
+ uuid_copy(*(host->node_id), *node_id);
609
+ }
610
611
if (unlikely(!wc))
612
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)
622
RRDHOST *host = NULL;
623
int rc = 2;
624
625
+ char host_guid[GUID_LEN + 1];
626
+ uuid_unparse_lower(*host_id, host_guid);
627
+ rrd_wrlock();
628
+ host = rrdhost_find_by_guid(host_guid);
629
+ if (likely(host))
630
+ set_host_node_id(host, node_id);
631
+ rrd_unlock();
632
+
633
if (unlikely(!db_meta)) {
634
if (default_rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE)
635
error_report("Database has not been initialized");
@@ -646,14 +659,6 @@ int update_node_id(uuid_t *host_id, uuid_t *node_id)
659
error_report("Failed to store node instance information, rc = %d", rc);
660
rc = sqlite3_changes(db_meta);
661
649
- char host_guid[GUID_LEN + 1];
650
- uuid_unparse_lower(*host_id, host_guid);
651
- rrd_wrlock();
652
- host = rrdhost_find_by_guid(host_guid);
653
- if (likely(host))
654
- set_host_node_id(host, node_id);
655
- rrd_unlock();
656
-
662
failed:
663
if (unlikely(sqlite3_finalize(res) != SQLITE_OK))
664
error_report("Failed to finalize the prepared statement when storing node instance information");