Skip to content

Commit

Permalink
Add --vt-ref-insert-size
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmundell committed Jun 5, 2023
1 parent f428738 commit a930465
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
10 changes: 9 additions & 1 deletion src/gvmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1886,6 +1886,7 @@ gvmd (int argc, char** argv, char *env[])
static gchar *broker_address = NULL;
static gchar *feed_lock_path = NULL;
static int feed_lock_timeout = 0;
static int vt_ref_insert_size = VT_REF_INSERT_SIZE_DEFAULT;
static gchar *vt_verification_collation = NULL;

GString *full_disable_commands = g_string_new ("");
Expand Down Expand Up @@ -2210,6 +2211,11 @@ gvmd (int argc, char** argv, char *env[])
&print_version,
"Print version and exit.",
NULL },
{ "vt-ref-insert-size", '\0', 0, G_OPTION_ARG_INT,
&vt_ref_insert_size,
"Max number of VT refs to insert per statement during VT update,"
" 0 for unlimited, default: "
G_STRINGIFY (VT_REF_INSERT_SIZE_DEFAULT), "<number>" },
{ "vt-verification-collation", '\0', 0, G_OPTION_ARG_STRING,
&vt_verification_collation,
"Set collation for VT verification to <collation>, omit or leave"
Expand Down Expand Up @@ -2293,10 +2299,12 @@ gvmd (int argc, char** argv, char *env[])
/* Set the connection auto retry */
set_scanner_connection_retry (scanner_connection_retry);

/* Set SecInfo update commit size */
/* Set SQL sizes */

set_secinfo_commit_size (secinfo_commit_size);

set_vt_ref_insert_size (vt_ref_insert_size);

/* Set VT verification collation override */
set_vt_verification_collation (vt_verification_collation);

Expand Down
28 changes: 20 additions & 8 deletions src/manage_sql_nvts.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@
*/
#define G_LOG_DOMAIN "md manage"

/**
* @brief Rows per statement when inserting VT refs for update/rebuild.
*
* There are about 500k vt_refs.
*/
#define VT_REFS_BATCH_SIZE 50000


/* Headers from backend specific manage_xxx.c file. */

Expand All @@ -66,6 +59,11 @@ create_tables_nvt (const gchar *);

/* NVT related global options */

/**
* @brief Max number of rows inserted per statement.
*/
static int vt_ref_insert_size = VT_REF_INSERT_SIZE_DEFAULT;

/**
* @brief File socket for OSP NVT update.
*/
Expand Down Expand Up @@ -129,6 +127,20 @@ check_osp_vt_update_socket ()

/* NVT's. */

/**
* @brief Set the VT ref insert size.
*
* @param new_size New size.
*/
void
set_vt_ref_insert_size (int new_size)
{
if (new_size < 0)
vt_ref_insert_size = 0;
else
vt_ref_insert_size = new_size;
}

/**
* @brief Ensures the sanity of nvts cache in DB.
*/
Expand Down Expand Up @@ -1721,7 +1733,7 @@ update_nvts_from_vts (element_t *get_vts_response,
* To solve both cases, we remove all nvt_preferences. */
sql ("TRUNCATE nvt_preferences;");

vt_refs_batch = batch_start (VT_REFS_BATCH_SIZE);
vt_refs_batch = batch_start (vt_ref_insert_size);
vt = element_first_child (vts);
while (vt)
{
Expand Down
8 changes: 8 additions & 0 deletions src/manage_sql_nvts.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@
{ NULL, NULL, KEYWORD_TYPE_UNKNOWN } \
}

/**
* @brief Default for vt_ref_insert_size.
*/
#define VT_REF_INSERT_SIZE_DEFAULT 50000

void
set_vt_ref_insert_size (int);

const char *
get_osp_vt_update_socket ();

Expand Down

0 comments on commit a930465

Please sign in to comment.