subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From phi...@apache.org
Subject svn commit: r1137660 - in /subversion/trunk/subversion: include/svn_error_codes.h libsvn_fs_fs/rep-cache-db.sql libsvn_fs_fs/rep-cache.c libsvn_subr/sqlite.c
Date Mon, 20 Jun 2011 15:25:20 GMT
Author: philip
Date: Mon Jun 20 15:25:20 2011
New Revision: 1137660

URL: http://svn.apache.org/viewvc?rev=1137660&view=rev
Log:
When updating the rep-cache database only look for existing rows if
the insert fails.  This means adding new representations requires only
one statement instead of two.

* subversion/libsvn_subr/sqlite.c
  (SQLITE_ERROR_CODE): Add SQLITE_CONSTRAINT.

* subversion/include/svn_error_codes.h
  (SVN_ERR_SQLITE_CONSTRAINT): New.

* subversion/libsvn_fs_fs/rep-cache.c
  (svn_fs_fs__set_rep_reference): Insert first, check existing only on fail.

* subversion/libsvn_fs_fs/rep-cache-db.sql
  (STMT_GET_REP): Remove trailing semi-colon.
  (STMT_SET_REP): Add "OR FAIL".

Modified:
    subversion/trunk/subversion/include/svn_error_codes.h
    subversion/trunk/subversion/libsvn_fs_fs/rep-cache-db.sql
    subversion/trunk/subversion/libsvn_fs_fs/rep-cache.c
    subversion/trunk/subversion/libsvn_subr/sqlite.c

Modified: subversion/trunk/subversion/include/svn_error_codes.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_error_codes.h?rev=1137660&r1=1137659&r2=1137660&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_error_codes.h (original)
+++ subversion/trunk/subversion/include/svn_error_codes.h Mon Jun 20 15:25:20 2011
@@ -1365,6 +1365,11 @@ SVN_ERROR_START
              "SQLite busy at transaction rollback; "
              "resetting all busy SQLite statements to allow rollback")
 
+  /** @since New in 1.7. */
+  SVN_ERRDEF(SVN_ERR_SQLITE_CONSTRAINT,
+             SVN_ERR_MISC_CATEGORY_START + 35,
+             "Constraint error in SQLite db")
+
   /* command-line client errors */
 
   SVN_ERRDEF(SVN_ERR_CL_ARG_PARSING_ERROR,

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=1137660&r1=1137659&r2=1137660&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs_fs/rep-cache-db.sql (original)
+++ subversion/trunk/subversion/libsvn_fs_fs/rep-cache-db.sql Mon Jun 20 15:25:20 2011
@@ -39,9 +39,9 @@ PRAGMA USER_VERSION = 1;
 -- STMT_GET_REP
 SELECT revision, offset, size, expanded_size
 FROM rep_cache
-WHERE hash = ?1;
+WHERE hash = ?1
 
 
 -- STMT_SET_REP
-INSERT INTO rep_cache (hash, revision, offset, size, expanded_size)
-VALUES (?1, ?2, ?3, ?4, ?5);
+INSERT OR FAIL INTO rep_cache (hash, revision, offset, size, expanded_size)
+VALUES (?1, ?2, ?3, ?4, ?5)

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=1137660&r1=1137659&r2=1137660&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs_fs/rep-cache.c (original)
+++ subversion/trunk/subversion/libsvn_fs_fs/rep-cache.c Mon Jun 20 15:25:20 2011
@@ -150,6 +150,7 @@ svn_fs_fs__set_rep_reference(svn_fs_t *f
   fs_fs_data_t *ffd = fs->fsap_data;
   representation_t *old_rep;
   svn_sqlite__stmt_t *stmt;
+  svn_error_t *err;
 
   SVN_ERR_ASSERT(ffd->rep_sharing_allowed);
   if (! ffd->rep_cache_db)
@@ -161,20 +162,37 @@ svn_fs_fs__set_rep_reference(svn_fs_t *f
                             _("Only SHA1 checksums can be used as keys in the "
                               "rep_cache table.\n"));
 
-  /* Check to see if we already have a mapping for REP->SHA1_CHECKSUM.  If so,
-     and the value is the same one we were about to write, that's
-     cool -- just do nothing.  If, however, the value is *different*,
-     that's a red flag!  */
-  SVN_ERR(svn_fs_fs__get_rep_reference(&old_rep, fs, rep->sha1_checksum, pool));
+  SVN_ERR(svn_sqlite__get_statement(&stmt, ffd->rep_cache_db, STMT_SET_REP));
+  SVN_ERR(svn_sqlite__bindf(stmt, "siiii",
+                            svn_checksum_to_cstring(rep->sha1_checksum, pool),
+                            (apr_int64_t) rep->revision,
+                            (apr_int64_t) rep->offset,
+                            (apr_int64_t) rep->size,
+                            (apr_int64_t) rep->expanded_size));
 
-  if (old_rep)
+  err = svn_sqlite__insert(NULL, stmt);
+  if (err)
     {
-      if ( reject_dup && ((old_rep->revision != rep->revision)
-            || (old_rep->offset != rep->offset)
-            || (old_rep->size != rep->size)
-            || (old_rep->expanded_size != rep->expanded_size)) )
-        return svn_error_createf(SVN_ERR_FS_CORRUPT, NULL,
-                 apr_psprintf(pool,
+      if (err->apr_err != SVN_ERR_SQLITE_CONSTRAINT)
+        return svn_error_return(err);
+
+      svn_error_clear(err);
+
+      /* Check to see if we already have a mapping for
+         REP->SHA1_CHECKSUM.  If so, and the value is the same one we
+         were about to write, that's cool -- just do nothing.  If,
+         however, the value is *different*, that's a red flag!  */
+      SVN_ERR(svn_fs_fs__get_rep_reference(&old_rep, fs, rep->sha1_checksum,
+                                           pool));
+
+      if (old_rep)
+        {
+          if (reject_dup && ((old_rep->revision != rep->revision)
+                             || (old_rep->offset != rep->offset)
+                             || (old_rep->size != rep->size)
+                             || (old_rep->expanded_size != rep->expanded_size)))
+            return svn_error_createf(SVN_ERR_FS_CORRUPT, NULL,
+                                     apr_psprintf(pool,
                               _("Representation key for checksum '%%s' exists "
                                 "in filesystem '%%s' with a different value "
                                 "(%%ld,%%%s,%%%s,%%%s) than what we were about "
@@ -186,17 +204,10 @@ svn_fs_fs__set_rep_reference(svn_fs_t *f
                  fs->path, old_rep->revision, old_rep->offset, old_rep->size,
                  old_rep->expanded_size, rep->revision, rep->offset, rep->size,
                  rep->expanded_size);
-      else
-        return SVN_NO_ERROR;
+          else
+            return SVN_NO_ERROR;
+        }
     }
 
-  SVN_ERR(svn_sqlite__get_statement(&stmt, ffd->rep_cache_db, STMT_SET_REP));
-  SVN_ERR(svn_sqlite__bindf(stmt, "siiii",
-                            svn_checksum_to_cstring(rep->sha1_checksum, pool),
-                            (apr_int64_t) rep->revision,
-                            (apr_int64_t) rep->offset,
-                            (apr_int64_t) rep->size,
-                            (apr_int64_t) rep->expanded_size));
-
-  return svn_sqlite__insert(NULL, stmt);
+  return SVN_NO_ERROR;
 }

Modified: subversion/trunk/subversion/libsvn_subr/sqlite.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/sqlite.c?rev=1137660&r1=1137659&r2=1137660&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/sqlite.c (original)
+++ subversion/trunk/subversion/libsvn_subr/sqlite.c Mon Jun 20 15:25:20 2011
@@ -106,11 +106,13 @@ struct svn_sqlite__value_t
 
 
 /* Convert SQLite error codes to SVN. Evaluates X multiple times */
-#define SQLITE_ERROR_CODE(x) ((x) == SQLITE_READONLY       \
-                              ? SVN_ERR_SQLITE_READONLY    \
-                              : ((x) == SQLITE_BUSY        \
-                                 ? SVN_ERR_SQLITE_BUSY     \
-                                 : SVN_ERR_SQLITE_ERROR) )
+#define SQLITE_ERROR_CODE(x) ((x) == SQLITE_READONLY            \
+                              ? SVN_ERR_SQLITE_READONLY         \
+                              : ((x) == SQLITE_BUSY             \
+                                 ? SVN_ERR_SQLITE_BUSY          \
+                                 : ((x) == SQLITE_CONSTRAINT    \
+                                    ? SVN_ERR_SQLITE_CONSTRAINT \
+                                    : SVN_ERR_SQLITE_ERROR)))
 
 
 /* SQLITE->SVN quick error wrap, much like SVN_ERR. */



Mime
View raw message