@cryptotaxi247 / netdata-1 / commits / dc2ccfe5e

Store null claim id in the database for non claimed children (#11036)

Stelios Fragkakis committed Apr 26, 2021 at 14:23 UTC dc2ccfe5eab7dc35165d8c8718d32d24d208022f
3 files changed +7 -7
claim/claim.c
+1 -2
@@ -165,8 +165,7 @@ void load_claiming_state(void)
165 }
166 localhost->aclk_state.claimed_id = claimed_id;
167
168 - if (likely(claimed_id))
169 - store_claim_id(&localhost->host_uuid, &uuid);
168 + store_claim_id(&localhost->host_uuid, claimed_id ? &uuid : NULL);
169
170 rrdhost_aclk_state_unlock(localhost);
171 if (!claimed_id) {
database/sqlite/sqlite_functions.c
+5 -3
@@ -1341,8 +1341,7 @@ failed:
1341
1342 #define SQL_STORE_CLAIM_ID "insert into node_instance " \
1343 "(host_id, claim_id, date_created) values (@host_id, @claim_id, strftime('%s')) " \
1344 - "on conflict(host_id) do update set node_id = null, claim_id = excluded.claim_id " \
1345 - "where claim_id <> excluded.claim_id;"
1344 + "on conflict(host_id) do update set claim_id = excluded.claim_id;"
1345
1346 void store_claim_id(uuid_t *host_id, uuid_t *claim_id)
1347 {
@@ -1367,7 +1366,10 @@ void store_claim_id(uuid_t *host_id, uuid_t *claim_id)
1366 goto failed;
1367 }
1368
1370 - rc = sqlite3_bind_blob(res, 2, claim_id, sizeof(*claim_id), SQLITE_STATIC);
1369 + if (claim_id)
1370 + rc = sqlite3_bind_blob(res, 2, claim_id, sizeof(*claim_id), SQLITE_STATIC);
1371 + else
1372 + rc = sqlite3_bind_null(res, 2);
1373 if (unlikely(rc != SQLITE_OK)) {
1374 error_report("Failed to bind claim_id parameter to store node instance information");
1375 goto failed;
streaming/receiver.c
+1 -2
@@ -131,8 +131,7 @@ PARSER_RC streaming_claimed_id(char **words, void *user, PLUGINSD_ACTION *plugin
131 freez(host->aclk_state.claimed_id);
132 host->aclk_state.claimed_id = strcmp(words[2], "NULL") ? strdupz(words[2]) : NULL;
133
134 - if (likely(host->aclk_state.claimed_id))
135 - store_claim_id(&host->host_uuid, &uuid);
134 + store_claim_id(&host->host_uuid, host->aclk_state.claimed_id ? &uuid : NULL);
135
136 rrdhost_aclk_state_unlock(host);
137