Skip to content

Commit

Permalink
wait for node_id while claiming (#15526)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsaou committed Jul 25, 2023
1 parent 4ad42d5 commit 2d23be7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
8 changes: 4 additions & 4 deletions claim/claim.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,12 @@ int api_v2_claim(struct web_client *w, char *url) {
int ms = 0;
do {
status = cloud_status();
if (status == CLOUD_STATUS_ONLINE)
if (status == CLOUD_STATUS_ONLINE && __atomic_load_n(&localhost->node_id, __ATOMIC_RELAXED))
break;

sleep_usec(100 * USEC_PER_MS);
ms += 100;
} while (ms < 5000);
sleep_usec(50 * USEC_PER_MS);
ms += 50;
} while (ms < 10000);
}
break;

Expand Down
29 changes: 17 additions & 12 deletions database/sqlite/sqlite_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 2d23be7

Please sign in to comment.