summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStelios Fragkakis <52996999+stelfrag@users.noreply.github.com>2022-05-31 15:17:37 +0300
committerGitHub <noreply@github.com>2022-05-31 15:17:37 +0300
commitaa074a3340f94dca7190bc1b73310703594ee42d (patch)
tree53c67b37bdebec8c510348c914372e368ae48269
parent811a28d20453c95cfb758d83884d971d181c6631 (diff)
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
-rw-r--r--database/sqlite/sqlite_functions.c10
-rw-r--r--database/sqlite/sqlite_functions.h1
2 files changed, 6 insertions, 5 deletions
diff --git a/database/sqlite/sqlite_functions.c b/database/sqlite/sqlite_functions.c
index 84fb1375f7..502633c679 100644
--- a/database/sqlite/sqlite_functions.c
+++ b/database/sqlite/sqlite_functions.c
@@ -73,10 +73,12 @@ static uv_mutex_t sqlite_transaction_lock;
int execute_insert(sqlite3_stmt *res)
{
int rc;
-
- while ((rc = sqlite3_step(res)) != SQLITE_DONE && unlikely(netdata_exit)) {
- if (likely(rc == SQLITE_BUSY || rc == SQLITE_LOCKED))
+ int cnt = 0;
+ while ((rc = sqlite3_step(res)) != SQLITE_DONE && ++cnt < SQL_MAX_RETRY && likely(!netdata_exit)) {
+ if (likely(rc == SQLITE_BUSY || rc == SQLITE_LOCKED)) {
usleep(SQLITE_INSERT_DELAY * USEC_PER_MS);
+ error_report("Failed to insert/update, rc = %d -- attempt %d", rc, cnt);
+ }
else {
error_report("SQLite error %d", rc);
break;
@@ -1288,8 +1290,6 @@ failed:
return host;
}
-#define SQL_MAX_RETRY 100
-
void db_execute(const char *cmd)
{
int rc;
diff --git a/database/sqlite/sqlite_functions.h b/database/sqlite/sqlite_functions.h
index 88c759707c..d244847749 100644
--- a/database/sqlite/sqlite_functions.h
+++ b/database/sqlite/sqlite_functions.h
@@ -24,6 +24,7 @@ typedef enum db_check_action_type {
DB_CHECK_CONT = 0x00008
} db_check_action_type_t;
+#define SQL_MAX_RETRY (100)
#define SQLITE_INSERT_DELAY (50) // Insert delay in case of lock
#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);"