[svn-commits] elguero: trunk r419222 - in /trunk: include/asterisk/astdb.h main/db.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jul 22 13:56:08 CDT 2014


Author: elguero
Date: Tue Jul 22 13:56:00 2014
New Revision: 419222

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=419222
Log:
core/db: Improve I/O When Updating Rows

When updating a row, we are currently doing an INSERT OR REPLACE INTO.  The
downside to this is that the row is deleted if it exists and then a new row is
inserted.  So, we are hitting the disk twice.  One for the deletion and one for
the insertion.

This patch changes this statement to an INSERT INTO and if the insert fails
because a row with that key exists, we will IGNORE the failure.  Then we will
attempt to perform an UPDATE on the existing row if that row wasn't just
INSERTed.

ASTERISK-24050 #close
Reported by: Michael L. Young
patches:
  astdb-insert-update-io-help_trunk_v2.diff
                                     uploaded by Michael L. Young (license 5026)

Review: https://reviewboard.asterisk.org/r/3815/

Modified:
    trunk/include/asterisk/astdb.h
    trunk/main/db.c

Modified: trunk/include/asterisk/astdb.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/astdb.h?view=diff&rev=419222&r1=419221&r2=419222
==============================================================================
--- trunk/include/asterisk/astdb.h (original)
+++ trunk/include/asterisk/astdb.h Tue Jul 22 13:56:00 2014
@@ -50,7 +50,14 @@
  */
 int ast_db_get_allocated(const char *family, const char *key, char **out);
 
-/*! \brief Store value addressed by family/key */
+/*! \brief Store value addressed by family/key
+ *
+ *  Try to insert a row first.  If a row already exists with the given key
+ *  we will then perform an update on this row.
+ *
+ *  The attempt here is to increase disk I/O performance by not deleting an existing
+ *  row and then inserting a new row when one already exists.
+ */
 int ast_db_put(const char *family, const char *key, const char *value);
 
 /*! \brief Delete entry in astdb */

Modified: trunk/main/db.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/db.c?view=diff&rev=419222&r1=419221&r2=419222
==============================================================================
--- trunk/main/db.c (original)
+++ trunk/main/db.c Tue Jul 22 13:56:00 2014
@@ -119,7 +119,7 @@
 #define DEFINE_SQL_STATEMENT(stmt,sql) static sqlite3_stmt *stmt; \
 	const char stmt##_sql[] = sql;
 
-DEFINE_SQL_STATEMENT(put_stmt, "INSERT OR REPLACE INTO astdb (key, value) VALUES (?, ?)")
+DEFINE_SQL_STATEMENT(put_stmt, "INSERT OR IGNORE INTO astdb (key, value) VALUES (?1, ?2); UPDATE astdb SET value=?2 WHERE changes()=0 AND key=?1")
 DEFINE_SQL_STATEMENT(get_stmt, "SELECT value FROM astdb WHERE key=?")
 DEFINE_SQL_STATEMENT(del_stmt, "DELETE FROM astdb WHERE key=?")
 DEFINE_SQL_STATEMENT(deltree_stmt, "DELETE FROM astdb WHERE key || '/' LIKE ? || '/' || '%'")




More information about the svn-commits mailing list