Skip to content

Commit

Permalink
Fix: Avoid DB check inserts in cleanup-sequences
Browse files Browse the repository at this point in the history
When running gvmd with the --optimize=cleanup-sequences option, the
database checks during initialization will avoid most inserts.
Setting database_version and max_hosts in the meta table now uses
INSERT ... ON CONFLICT instead of deleting the previous entry.

Skipping the inserts prevents the cleanup failing if one of the
sequence has already run out of ids.
The change to the meta table update reduces the risk of the meta table
id sequence running out.
  • Loading branch information
timopollmeier committed Nov 26, 2024
1 parent 25d41de commit 20ec707
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 58 deletions.
9 changes: 6 additions & 3 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,8 @@ int
manage_create_encryption_key (GSList *log_config,
const db_conn_info_t *database)
{
int ret = manage_option_setup (log_config, database);
int ret = manage_option_setup (log_config, database,
0 /* avoid_db_check_inserts */);
if (ret)
{
printf ("Error setting up log config or database connection.");
Expand Down Expand Up @@ -1042,7 +1043,8 @@ manage_set_encryption_key (GSList *log_config,
const db_conn_info_t *database,
const char *uid)
{
int ret = manage_option_setup (log_config, database);
int ret = manage_option_setup (log_config, database,
0 /* avoid_db_check_inserts */);
if (ret)
{
printf ("Error setting up log config or database connection.\n");
Expand Down Expand Up @@ -5707,7 +5709,8 @@ manage_rebuild_gvmd_data_from_feed (const char *types,
return -1;
}

ret = manage_option_setup (log_config, database);
ret = manage_option_setup (log_config, database,
0 /* avoid_db_check_inserts */);
if (ret)
{
if (error_msg)
Expand Down
2 changes: 1 addition & 1 deletion src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ init_manage (GSList*, const db_conn_info_t *, int, int, int, int,
manage_connection_forker_t, int);

int
init_manage_helper (GSList *, const db_conn_info_t *, int);
init_manage_helper (GSList *, const db_conn_info_t *, int, int);

void
init_manage_process (const db_conn_info_t*);
Expand Down
Loading

0 comments on commit 20ec707

Please sign in to comment.