Always update last_disk_db_idx after storing queries on disk as sqlite3_changes() sometimes reports to few rows being inserted. This was a rather tedious debugging...

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2023-02-25 18:22:55 +01:00
parent ce96c5baef
commit 4ea0bf7dea
No known key found for this signature in database
GPG Key ID: 00135ACBD90B28DD
4 changed files with 23 additions and 3 deletions

View File

@ -38,11 +38,14 @@ FILE * __attribute((malloc)) __attribute((nonnull(1))) openFTLtoml(const char *m
// Lock file, may block if the file is currently opened
if(flock(fileno(fp), LOCK_EX) != 0)
{
const int _e = errno;
log_err("Cannot open FTL's config file in exclusive mode: %s", strerror(errno));
fclose(fp);
errno = _e;
return NULL;
}
errno = 0;
return fp;
}

View File

@ -100,7 +100,7 @@ static toml_table_t *parseTOML(void)
if((fp = openFTLtoml("r")) == NULL)
{
log_warn("No config file available (%s), using defaults",
strerror(errno));
strerror(errno));
return NULL;
}

View File

@ -29,7 +29,7 @@ bool writeFTLtoml(const bool verbose)
FILE *fp;
if((fp = openFTLtoml("w")) == NULL)
{
log_warn("Cannot write to FTL config file, content not updated");
log_warn("Cannot write to FTL config file (%s), content not updated", strerror(errno));
// Restart watching for changes in the config file
watch_config(true);
return false;

View File

@ -455,6 +455,23 @@ bool export_queries_to_disk(bool final)
sqlite3_reset(stmt);
sqlite3_finalize(stmt);
// Update last_disk_db_idx
// Prepare SQLite3 statement
rc = sqlite3_prepare_v2(memdb, "SELECT MAX(id) FROM disk.query_storage;", -1, &stmt, NULL);
// Perform step
if((rc = sqlite3_step(stmt)) == SQLITE_ROW)
last_disk_db_idx = sqlite3_column_int64(stmt, 0);
else
log_err("Failed to get MAX(id) from query_storage: %s",
sqlite3_errstr(rc));
// Finalize statement
sqlite3_reset(stmt);
sqlite3_finalize(stmt);
// Export linking tables and current AUTOINCREMENT values to the disk database
const char *subtable_names[] = {
"domain_by_id",
@ -1029,7 +1046,7 @@ void DB_read_queries(void)
if((rc = sqlite3_step(stmt)) == SQLITE_ROW)
last_disk_db_idx = sqlite3_column_int64(stmt, 0);
else
log_err("DB_read_queries(): Failed to get MAX(id) from queries: %s",
log_err("DB_read_queries(): Failed to get MAX(id) from disk.query_storage: %s",
sqlite3_errstr(rc));
// Finalize statement