[vlc-commits] sql_medial_lib: add option to disable on-disk transactions.

Francois Cartegnie git at videolan.org
Fri Sep 14 14:35:11 CEST 2012


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Sep 14 14:24:59 2012 +0200| [e488b28c67fe901fd7db6a4523fa0f7e5fed8ce8] | committer: Francois Cartegnie

sql_medial_lib: add option to disable on-disk transactions.

Tradeoff for large inserts that can cause heavy disk I/O due to the
transactions. ML is a non-critical database.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e488b28c67fe901fd7db6a4523fa0f7e5fed8ce8
---

 modules/gui/qt4/dialogs/ml_configuration.cpp |    9 ++++++-
 modules/gui/qt4/dialogs/ml_configuration.hpp |    1 +
 modules/media_library/sql_media_library.c    |   33 ++++++++++++++++++++++++++
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/modules/gui/qt4/dialogs/ml_configuration.cpp b/modules/gui/qt4/dialogs/ml_configuration.cpp
index f3f8b99..6b56c8b 100644
--- a/modules/gui/qt4/dialogs/ml_configuration.cpp
+++ b/modules/gui/qt4/dialogs/ml_configuration.cpp
@@ -221,6 +221,8 @@ MLConfDialog::MLConfDialog( QWidget *parent, intf_thread_t *_p_intf )
     /* recursivity */
     recursivity = new QCheckBox( qtr( "Subdirectory recursive scanning" ) );
 
+    synchronous = new QCheckBox( qtr( "Use safe transactions" ) );
+
     /* Buttons */
     QDialogButtonBox *buttonsBox = new QDialogButtonBox();
     QPushButton *save = new QPushButton( qtr( "&Save" ) );
@@ -233,7 +235,8 @@ MLConfDialog::MLConfDialog( QWidget *parent, intf_thread_t *_p_intf )
 
     main_layout->addWidget( tree, 0, 0 );
     main_layout->addWidget( recursivity, 1, 0 );
-    main_layout->addWidget( buttonsBox, 2, 0 );
+    main_layout->addWidget( synchronous, 2, 0 );
+    main_layout->addWidget( buttonsBox, 3, 0 );
 
     p_ml = ml_Get( p_intf );
     init();
@@ -249,6 +252,9 @@ void MLConfDialog::init()
     bool b_recursive = var_CreateGetBool( p_ml, "ml-recursive-scan" );
     recursivity->setChecked( b_recursive );
 
+    bool b_sync = var_CreateGetBool( p_ml, "ml-synchronous" );
+    synchronous->setChecked( b_sync );
+
     if( p_monitored_dirs )
         vlc_array_destroy( p_monitored_dirs );
     p_monitored_dirs = vlc_array_new();
@@ -281,6 +287,7 @@ void MLConfDialog::save()
     }
 
     var_SetBool( p_ml, "ml-recursive-scan", recursivity->isChecked() );
+    var_SetBool( p_ml, "ml-synchronous", synchronous->isChecked() );
 
     init();
     hide();
diff --git a/modules/gui/qt4/dialogs/ml_configuration.hpp b/modules/gui/qt4/dialogs/ml_configuration.hpp
index 5cefc6d..145d279 100644
--- a/modules/gui/qt4/dialogs/ml_configuration.hpp
+++ b/modules/gui/qt4/dialogs/ml_configuration.hpp
@@ -97,6 +97,7 @@ private:
 
     MLDirModel *model;
     QCheckBox *recursivity;
+    QCheckBox *synchronous;
 
     static MLConfDialog *instance;
 
diff --git a/modules/media_library/sql_media_library.c b/modules/media_library/sql_media_library.c
index 55546ea..6a5788d 100644
--- a/modules/media_library/sql_media_library.c
+++ b/modules/media_library/sql_media_library.c
@@ -129,6 +129,8 @@ vlc_module_begin()
             RECURSIVE_LONGTEXT, false )
     add_bool( "ml-auto-add", true,  N_("Auto add new medias"),
             N_( "Automatically add new medias to ML" ), false )
+    add_bool( "ml-synchronous", true,  N_("Use transactions"),
+            N_( "Disabling transactions saves I/O but can corrupt database in case of crash" ), false )
 vlc_module_end()
 
 
@@ -1033,6 +1035,33 @@ quit_createemptydatabase:
     return VLC_SUCCESS;
 }
 
+/**
+ * @brief Journal and synchronous disc and writes
+ *
+ * @param p_ml media library object
+ * @param b_sync boolean
+ * @return <= 0 on error.
+ */
+static int SetSynchronous( media_library_t *p_ml, bool b_sync )
+{
+    int i_rows, i_cols;
+    char **pp_results;
+    int i_return;
+    if ( b_sync )
+        i_return = Query( p_ml, &pp_results, &i_rows, &i_cols,
+            "PRAGMA synchronous = ON;PRAGMA journal_mode = TRUNCATE" );
+    else
+        i_return = Query( p_ml, &pp_results, &i_rows, &i_cols,
+            "PRAGMA synchronous = OFF;PRAGMA journal_mode = MEMORY" );
+    if( i_return != VLC_SUCCESS )
+        i_return = -1;
+    else
+        i_return = atoi( pp_results[ 1 ] );
+
+    FreeSQLResult( p_ml, pp_results );
+
+    return i_return;
+}
 
 /**
  * @brief Initiates database (create the database and the tables if needed)
@@ -1048,10 +1077,12 @@ int InitDatabase( media_library_t *p_ml )
     /* Select database name */
     char *psz_dbhost = NULL, *psz_user = NULL, *psz_pass = NULL;
     int i_port = 0;
+    bool b_sync = false;
     psz_dbhost = config_GetPsz( p_ml, "ml-filename" );
     psz_user = config_GetPsz( p_ml, "ml-username" );
     psz_pass = config_GetPsz( p_ml, "ml-password" );
     i_port = config_GetInt( p_ml, "ml-port" );
+    b_sync = config_GetInt( p_ml, "ml-synchronous" );
 
     /* Let's consider that a filename with a DIR_SEP is a full URL */
     if( strchr( psz_dbhost, DIR_SEP_CHAR ) == NULL )
@@ -1090,6 +1121,8 @@ int InitDatabase( media_library_t *p_ml )
 #error "ML versioning code needs to be updated. Is this done correctly?"
 #endif
 
+    SetSynchronous( p_ml, b_sync );
+
     msg_Dbg( p_ml, "ML initialized" );
     return VLC_SUCCESS;
 }



More information about the vlc-commits mailing list