@cryptotaxi247 / netdata-1 / commits / aa074a334

Fix the retry count and netdata_exit check when running an sqlite3_step command (#13040)

* Move retry count to the header file * Add SQL_MAX_RETRY count and fix the netdata_exit check

Stelios Fragkakis committed May 31, 2022 at 15:17 UTC aa074a3340f94dca7190bc1b73310703594ee42d
2 files changed +6 -5
database/sqlite/sqlite_functions.c
+5 -5
@@ -73,10 +73,12 @@ static uv_mutex_t sqlite_transaction_lock;
73 int execute_insert(sqlite3_stmt *res)
74 {
75 int rc;
76 -
77 - while ((rc = sqlite3_step(res)) != SQLITE_DONE && unlikely(netdata_exit)) {
78 - if (likely(rc == SQLITE_BUSY || rc == SQLITE_LOCKED))
76 + int cnt = 0;
77 + while ((rc = sqlite3_step(res)) != SQLITE_DONE && ++cnt < SQL_MAX_RETRY && likely(!netdata_exit)) {
78 + if (likely(rc == SQLITE_BUSY || rc == SQLITE_LOCKED)) {
79 usleep(SQLITE_INSERT_DELAY * USEC_PER_MS);
80 + error_report("Failed to insert/update, rc = %d -- attempt %d", rc, cnt);
81 + }
82 else {
83 error_report("SQLite error %d", rc);
84 break;
@@ -1288,8 +1290,6 @@ failed:
1290 return host;
1291 }
1292
1291 -#define SQL_MAX_RETRY 100
1292 -
1293 void db_execute(const char *cmd)
1294 {
1295 int rc;
database/sqlite/sqlite_functions.h
+1
@@ -24,6 +24,7 @@ typedef enum db_check_action_type {
24 DB_CHECK_CONT = 0x00008
25 } db_check_action_type_t;
26
27 +#define SQL_MAX_RETRY (100)
28 #define SQLITE_INSERT_DELAY (50) // Insert delay in case of lock
29
30 #define SQL_STORE_HOST "insert or replace into host (host_id,hostname,registry_hostname,update_every,os,timezone,tags) values (?1,?2,?3,?4,?5,?6,?7);"