Try to find worker thread from parked ones (#11928)
Emmanuel Vasilakis committed
Jan 11, 2022 at 15:42 UTC
bf023b50febe30c5a43db941a4af00f6daa3682e
4 files changed
+25
-2
database/sqlite/sqlite_aclk.c
+18
@@ -189,6 +189,24 @@ int aclk_worker_enq_cmd(char *node_id, struct aclk_database_cmd *cmd)
189
return (wc == NULL);
190
}
191
192
+struct aclk_database_worker_config *find_inactive_wc_by_node_id(char *node_id)
193
+{
194
+ if (unlikely(!node_id))
195
+ return NULL;
196
+
197
+ uv_mutex_lock(&aclk_async_lock);
198
+ struct aclk_database_worker_config *wc = aclk_thread_head;
199
+
200
+ while (wc) {
201
+ if (!strcmp(wc->node_id, node_id))
202
+ break;
203
+ wc = wc->next;
204
+ }
205
+ uv_mutex_unlock(&aclk_async_lock);
206
+
207
+ return (wc);
208
+}
209
+
210
void aclk_sync_exit_all()
211
{
212
rrd_wrlock();
database/sqlite/sqlite_aclk.h
+1
@@ -229,4 +229,5 @@ void sql_delete_aclk_table_list(struct aclk_database_worker_config *wc, struct a
229
void sql_maint_aclk_sync_database(struct aclk_database_worker_config *wc, struct aclk_database_cmd cmd);
230
int claimed();
231
void aclk_sync_exit_all();
232
+struct aclk_database_worker_config *find_inactive_wc_by_node_id(char *node_id);
233
#endif //NETDATA_SQLITE_ACLK_H
database/sqlite/sqlite_aclk_alert.c
+3
-1
@@ -546,7 +546,9 @@ void aclk_start_alert_streaming(char *node_id, uint64_t batch_id, uint64_t start
546
rrd_wrlock();
547
RRDHOST *host = find_host_by_node_id(node_id);
548
if (likely(host))
549
- wc = (struct aclk_database_worker_config *)host->dbsync_worker;
549
+ wc = (struct aclk_database_worker_config *)host->dbsync_worker ?
550
+ (struct aclk_database_worker_config *)host->dbsync_worker :
551
+ (struct aclk_database_worker_config *)find_inactive_wc_by_node_id(node_id);
552
rrd_unlock();
553
554
if (unlikely(!host->health_enabled)) {
database/sqlite/sqlite_aclk_chart.c
+3
-1
@@ -682,7 +682,9 @@ void aclk_start_streaming(char *node_id, uint64_t sequence_id, time_t created_at
682
while(host) {
683
if (host->node_id && !(uuid_compare(*host->node_id, node_uuid))) {
684
rrd_unlock();
685
- wc = (struct aclk_database_worker_config *)host->dbsync_worker;
685
+ wc = (struct aclk_database_worker_config *)host->dbsync_worker ?
686
+ (struct aclk_database_worker_config *)host->dbsync_worker :
687
+ (struct aclk_database_worker_config *)find_inactive_wc_by_node_id(node_id);
688
if (likely(wc)) {
689
wc->chart_reset_count++;
690
__sync_synchronize();