Author: stsp
Date: Tue Mar 31 08:12:59 2020
New Revision: 1875918

URL: http://svn.apache.org/viewvc?rev=1875918&view=rev
Log:
rep-cache.db insert optimization.

Use the 'IGNORE' conflict resolution algorithm [1] for STMT_SET_REP
and remove SVN_ERR_SQLITE_CONSTRAINT handling, because the error
should not occur now. It brings a slight performance improvement,
because we remove an extra svn_fs_fs__get_rep_reference() call.

The result of a synthetic benchmark, where 10000 identical entries
are inserted into a rep-cache.db which contains 250000 entries:
1) In the case of using the 'FAIL' algorithm: ~40000 microseconds.
2) In the case of using the 'IGNORE' algorithm: ~15000 microseconds.

[1] https://www.sqlite.org/lang_conflict.html

* subversion/libsvn_fs_fs/rep-cache-db.sql
  (STMT_SET_REP): Use the 'IGNORE' conflict resolution algorithm.
  
* subversion/libsvn_fs_fs/rep-cache.c
  (svn_fs_fs__set_rep_reference): Remove SVN_ERR_SQLITE_CONSTRAINT handling.

Patch by: Denis Kovalchuk <[email protected]>

Modified:
    subversion/trunk/subversion/libsvn_fs_fs/rep-cache-db.sql
    subversion/trunk/subversion/libsvn_fs_fs/rep-cache.c

Modified: subversion/trunk/subversion/libsvn_fs_fs/rep-cache-db.sql
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_fs_fs/rep-cache-db.sql?rev=1875918&r1=1875917&r2=1875918&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs_fs/rep-cache-db.sql (original)
+++ subversion/trunk/subversion/libsvn_fs_fs/rep-cache-db.sql Tue Mar 31 
08:12:59 2020
@@ -61,7 +61,7 @@ WHERE hash = ?1
 
 -- STMT_SET_REP
 /* Works for both V1 and V2 schemas. */
-INSERT OR FAIL INTO rep_cache (hash, revision, offset, size, expanded_size)
+INSERT OR IGNORE INTO rep_cache (hash, revision, offset, size, expanded_size)
 VALUES (?1, ?2, ?3, ?4, ?5)
 
 -- STMT_GET_REPS_FOR_RANGE

Modified: subversion/trunk/subversion/libsvn_fs_fs/rep-cache.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_fs_fs/rep-cache.c?rev=1875918&r1=1875917&r2=1875918&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs_fs/rep-cache.c (original)
+++ subversion/trunk/subversion/libsvn_fs_fs/rep-cache.c Tue Mar 31 08:12:59 
2020
@@ -328,7 +328,6 @@ svn_fs_fs__set_rep_reference(svn_fs_t *f
 {
   fs_fs_data_t *ffd = fs->fsap_data;
   svn_sqlite__stmt_t *stmt;
-  svn_error_t *err;
   svn_checksum_t checksum;
   checksum.kind = svn_checksum_sha1;
   checksum.digest = rep->sha1_digest;
@@ -351,28 +350,7 @@ svn_fs_fs__set_rep_reference(svn_fs_t *f
                             (apr_int64_t) rep->size,
                             (apr_int64_t) rep->expanded_size));
 
-  err = svn_sqlite__insert(NULL, stmt);
-  if (err)
-    {
-      representation_t *old_rep;
-
-      if (err->apr_err != SVN_ERR_SQLITE_CONSTRAINT)
-        return svn_error_trace(err);
-
-      svn_error_clear(err);
-
-      /* Constraint failed so the mapping for SHA1_CHECKSUM->REP
-         should exist.  If so that's cool -- just do nothing.  If not,
-         that's a red flag!  */
-      SVN_ERR(svn_fs_fs__get_rep_reference(&old_rep, fs, &checksum, pool));
-
-      if (!old_rep)
-        {
-          /* Something really odd at this point, we failed to insert the
-             checksum AND failed to read an existing checksum.  Do we need
-             to flag this? */
-        }
-    }
+  SVN_ERR(svn_sqlite__insert(NULL, stmt));
 
   return SVN_NO_ERROR;
 }


Reply via email to