0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-04-16 18:37:50 +00:00

Improve agent shutdown ()

* Clear detection thread on stop
Handle multi db close

* cancel_threads should be called once
This commit is contained in:
Stelios Fragkakis 2024-02-08 09:43:18 +02:00 committed by GitHub
parent 2e1ee5f821
commit e9760b43f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 13 additions and 2 deletions

View file

@ -691,6 +691,9 @@ static void set_nofile_limit(struct rlimit *rl) {
void cancel_main_threads() {
nd_log_limits_unlimited();
if (!static_threads)
return;
int i, found = 0;
usec_t max = 5 * USEC_PER_SEC, step = 100000;
for (i = 0; static_threads[i].name != NULL ; i++) {
@ -732,6 +735,7 @@ void cancel_main_threads() {
freez(static_threads[i].thread);
freez(static_threads);
static_threads = NULL;
}
static const struct option_def {

View file

@ -86,6 +86,7 @@ void sql_close_context_database(void)
rc = sqlite3_close_v2(db_context_meta);
if (unlikely(rc != SQLITE_OK))
error_report("Error %d while closing the context SQLite database, %s", rc, sqlite3_errstr(rc));
db_context_meta = NULL;
}
//

View file

@ -518,6 +518,7 @@ void sql_close_database(void)
rc = sqlite3_close_v2(db_meta);
if (unlikely(rc != SQLITE_OK))
error_report("Error %d while closing the SQLite database, %s", rc, sqlite3_errstr(rc));
db_meta = NULL;
}
int exec_statement_with_uuid(const char *sql, uuid_t *uuid)

View file

@ -1826,9 +1826,12 @@ void metadata_sync_shutdown(void)
void metadata_sync_shutdown_prepare(void)
{
if (unlikely(!metasync_worker.loop))
static bool running = false;
if (unlikely(!metasync_worker.loop || running))
return;
running = true;
struct metadata_cmd cmd;
memset(&cmd, 0, sizeof(cmd));

View file

@ -1805,12 +1805,13 @@ void ml_init()
}
void ml_fini() {
if (!Cfg.enable_anomaly_detection)
if (!Cfg.enable_anomaly_detection || !db)
return;
int rc = sqlite3_close_v2(db);
if (unlikely(rc != SQLITE_OK))
error_report("Error %d while closing the SQLite database, %s", rc, sqlite3_errstr(rc));
db = NULL;
}
void ml_start_threads() {
@ -1845,6 +1846,7 @@ void ml_stop_threads()
return;
netdata_thread_join(Cfg.detection_thread, NULL);
Cfg.detection_thread = 0;
// signal the training queue of each thread
for (size_t idx = 0; idx != Cfg.num_training_threads; idx++) {