Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wait for node_id while claiming #15526

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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