diff --git a/src/gvmd.c b/src/gvmd.c index a07e1f953..c5d73a51b 100644 --- a/src/gvmd.c +++ b/src/gvmd.c @@ -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 (""); @@ -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), "" }, { "vt-verification-collation", '\0', 0, G_OPTION_ARG_STRING, &vt_verification_collation, "Set collation for VT verification to , omit or leave" @@ -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); diff --git a/src/manage_sql_nvts.c b/src/manage_sql_nvts.c index 956a4a495..9cd32cb35 100644 --- a/src/manage_sql_nvts.c +++ b/src/manage_sql_nvts.c @@ -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. */ @@ -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. */ @@ -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. */ @@ -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) { diff --git a/src/manage_sql_nvts.h b/src/manage_sql_nvts.h index 2e58fb6f4..117b2a779 100644 --- a/src/manage_sql_nvts.h +++ b/src/manage_sql_nvts.h @@ -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 ();