You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by ju...@apache.org on 2011/01/13 12:58:53 UTC

svn commit: r1058523 - in /subversion/trunk/subversion: libsvn_subr/sqlite.c libsvn_wc/upgrade.c libsvn_wc/wc-metadata.sql libsvn_wc/wc-queries.sql libsvn_wc/wc.h libsvn_wc/wc_db.c tests/libsvn_wc/db-test.c tests/libsvn_wc/entries-compat.c

Author: julianfoad
Date: Thu Jan 13 11:58:52 2011
New Revision: 1058523

URL: http://svn.apache.org/viewvc?rev=1058523&view=rev
Log:
Implement reference counting for pristine texts in the WC DB, by using
SQLite triggers.  Bump the WC format and upgrade old development WCs by
initializing their reference counts.  This change causes the ref count to be
maintained; it does not use the ref count.

* subversion/libsvn_wc/wc-metadata.sql
  (PRISTINE): Update the documentation of the 'refcount' column.
  (nodes_insert_trigger, nodes_delete_trigger, nodes_update_checksum_trigger):
    New triggers that cause the appropriate reference count (or counts) to
    be incremented or decremented whenever a NODES table row containing a
    reference is inserted or deleted or modified.

* subversion/libsvn_subr/sqlite.c
  (svn_sqlite__open): Turn on recursive triggers in SQLite so that triggers
    will fire on both parts of an "INSERT OR REPLACE" statement.  This
    requires SQLite >= 3.6.18, which is enforced at build time by r1058479.

* subversion/libsvn_wc/wc-queries.sql
  (STMT_INSERT_PRISTINE): Initialize the ref count to 0 instead of 1.

* subversion/libsvn_wc/wc_db.c
  (create_db): Create the new triggers when creating the schema.

* subversion/tests/libsvn_wc/db-test.c,
  subversion/tests/libsvn_wc/entries-compat.c
  (create_fake_wc): Same.

* subversion/libsvn_wc/wc.h
  (SVN_WC__VERSION): Bump to 24.

* subversion/libsvn_wc/wc-metadata.sql
  (STMT_UPGRADE_TO_24): New statement, to initialize all ref counts.

* subversion/libsvn_wc/upgrade.c
  (bump_to_24): New function.
  (svn_wc__upgrade_sdb): Call it.

Modified:
    subversion/trunk/subversion/libsvn_subr/sqlite.c
    subversion/trunk/subversion/libsvn_wc/upgrade.c
    subversion/trunk/subversion/libsvn_wc/wc-metadata.sql
    subversion/trunk/subversion/libsvn_wc/wc-queries.sql
    subversion/trunk/subversion/libsvn_wc/wc.h
    subversion/trunk/subversion/libsvn_wc/wc_db.c
    subversion/trunk/subversion/tests/libsvn_wc/db-test.c
    subversion/trunk/subversion/tests/libsvn_wc/entries-compat.c

Modified: subversion/trunk/subversion/libsvn_subr/sqlite.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/sqlite.c?rev=1058523&r1=1058522&r2=1058523&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/sqlite.c (original)
+++ subversion/trunk/subversion/libsvn_subr/sqlite.c Thu Jan 13 11:58:52 2011
@@ -932,7 +932,11 @@ svn_sqlite__open(svn_sqlite__db_t **db, 
 
                  ### Maybe switch to NORMAL(1) when we use larger transaction
                      scopes */
-              "PRAGMA synchronous=OFF;"));
+              "PRAGMA synchronous=OFF;"
+              /* Enable recursive triggers so that a user trigger will fire
+               * in the deletion phase of an INSERT OR REPLACE statement.
+               * Requires SQLite >= 3.6.18 */
+              "PRAGMA recursive_triggers=ON;"));
 
 #if SQLITE_VERSION_AT_LEAST(3,6,19) && defined(SVN_DEBUG)
   /* When running in debug mode, enable the checking of foreign key

Modified: subversion/trunk/subversion/libsvn_wc/upgrade.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/upgrade.c?rev=1058523&r1=1058522&r2=1058523&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/upgrade.c (original)
+++ subversion/trunk/subversion/libsvn_wc/upgrade.c Thu Jan 13 11:58:52 2011
@@ -1129,6 +1129,14 @@ bump_to_23(void *baton, svn_sqlite__db_t
   return SVN_NO_ERROR;
 }
 
+static svn_error_t *
+bump_to_24(void *baton, svn_sqlite__db_t *sdb, apr_pool_t *scratch_pool)
+{
+  SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_UPGRADE_TO_24));
+  SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_CREATE_NODES_TRIGGERS));
+  return SVN_NO_ERROR;
+}
+
 
 struct upgrade_data_t {
   svn_sqlite__db_t *sdb;
@@ -1390,6 +1398,12 @@ svn_wc__upgrade_sdb(int *result_format,
         *result_format = 23;
         /* FALLTHROUGH  */
 
+      case 23:
+        SVN_ERR(svn_sqlite__with_transaction(sdb, bump_to_24, &bb,
+                                             scratch_pool));
+        *result_format = 24;
+        /* FALLTHROUGH  */
+
       /* ### future bumps go here.  */
 #if 0
       case XXX-1:

Modified: subversion/trunk/subversion/libsvn_wc/wc-metadata.sql
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc-metadata.sql?rev=1058523&r1=1058522&r2=1058523&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc-metadata.sql (original)
+++ subversion/trunk/subversion/libsvn_wc/wc-metadata.sql Thu Jan 13 11:58:52 2011
@@ -95,8 +95,9 @@ CREATE TABLE PRISTINE (
      Used to verify the pristine file is "proper". */
   size  INTEGER NOT NULL,
 
-  /* ### this will probably go away, in favor of counting references
-     ### that exist in NODES. Not yet used; always set to 1. */
+  /* The number of rows in the NODES table that have a 'checksum' column
+     value that refers to this row.  (References in other places, such as
+     in the ACTUAL_NODE table, are not counted.) */
   refcount  INTEGER NOT NULL,
 
   /* Alternative MD5 checksum used for communicating with older
@@ -480,6 +481,35 @@ CREATE TABLE NODES (
 CREATE INDEX I_NODES_PARENT ON NODES (wc_id, parent_relpath, op_depth);
 
 
+-- STMT_CREATE_NODES_TRIGGERS
+
+CREATE TRIGGER nodes_insert_trigger
+AFTER INSERT ON nodes
+/* WHEN NEW.checksum IS NOT NULL */
+BEGIN
+  UPDATE pristine SET refcount = refcount + 1
+  WHERE checksum = NEW.checksum;
+END;
+
+CREATE TRIGGER nodes_delete_trigger
+AFTER DELETE ON nodes
+/* WHEN OLD.checksum IS NOT NULL */
+BEGIN
+  UPDATE pristine SET refcount = refcount - 1
+  WHERE checksum = OLD.checksum;
+END;
+
+CREATE TRIGGER nodes_update_checksum_trigger
+AFTER UPDATE OF checksum ON nodes
+/* WHEN NEW.checksum IS NOT NULL OR OLD.checksum IS NOT NULL */
+BEGIN
+  UPDATE pristine SET refcount = refcount + 1
+  WHERE checksum = NEW.checksum;
+  UPDATE pristine SET refcount = refcount - 1
+  WHERE checksum = OLD.checksum;
+END;
+
+
 
 /* Format 20 introduces NODES and removes BASE_NODE and WORKING_NODE */
 
@@ -552,6 +582,19 @@ PRAGMA user_version = 23;
 
 /* ------------------------------------------------------------------------- */
 
+/* Format 24 involves no schema changes; it starts using the pristine
+   table's refcount column correctly. */
+
+-- STMT_UPGRADE_TO_24
+UPDATE pristine SET refcount =
+  (SELECT COUNT(*) FROM nodes
+   WHERE checksum = pristine.checksum /*OR checksum = pristine.md5_checksum*/);
+
+PRAGMA user_version = 24;
+
+
+/* ------------------------------------------------------------------------- */
+
 /* Format YYY introduces new handling for conflict information.  */
 -- format: YYY
 

Modified: subversion/trunk/subversion/libsvn_wc/wc-queries.sql
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc-queries.sql?rev=1058523&r1=1058522&r2=1058523&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc-queries.sql (original)
+++ subversion/trunk/subversion/libsvn_wc/wc-queries.sql Thu Jan 13 11:58:52 2011
@@ -411,7 +411,7 @@ DELETE FROM work_queue WHERE id = ?1;
 
 -- STMT_INSERT_PRISTINE
 INSERT OR IGNORE INTO pristine (checksum, md5_checksum, size, refcount)
-VALUES (?1, ?2, ?3, 1);
+VALUES (?1, ?2, ?3, 0);
 
 -- STMT_SELECT_PRISTINE_MD5_CHECKSUM
 SELECT md5_checksum

Modified: subversion/trunk/subversion/libsvn_wc/wc.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc.h?rev=1058523&r1=1058522&r2=1058523&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc.h (original)
+++ subversion/trunk/subversion/libsvn_wc/wc.h Thu Jan 13 11:58:52 2011
@@ -133,12 +133,15 @@ extern "C" {
  * The change from 22 to 23 introduced multi-layer op_depth processing for
  * NODES.
  *
+ * The change from 23 to 24 started using the 'refcount' column of the
+ * 'pristine' table correctly, instead of always setting it to '1'.
+ *
  * == 1.7.x shipped with format ???
  *
  * Please document any further format changes here.
  */
 
-#define SVN_WC__VERSION 23
+#define SVN_WC__VERSION 24
 
 
 /* Formats <= this have no concept of "revert text-base/props".  */

Modified: subversion/trunk/subversion/libsvn_wc/wc_db.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc_db.c?rev=1058523&r1=1058522&r2=1058523&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc_db.c (original)
+++ subversion/trunk/subversion/libsvn_wc/wc_db.c Thu Jan 13 11:58:52 2011
@@ -1273,9 +1273,8 @@ create_db(svn_sqlite__db_t **sdb,
 
   /* Create the database's schema.  */
   SVN_ERR(svn_sqlite__exec_statements(*sdb, STMT_CREATE_SCHEMA));
-
-  /* Create the NODES table for the experimental schema */
   SVN_ERR(svn_sqlite__exec_statements(*sdb, STMT_CREATE_NODES));
+  SVN_ERR(svn_sqlite__exec_statements(*sdb, STMT_CREATE_NODES_TRIGGERS));
 
   /* Insert the repository. */
   SVN_ERR(create_repos_id(repos_id, repos_root_url, repos_uuid, *sdb,

Modified: subversion/trunk/subversion/tests/libsvn_wc/db-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_wc/db-test.c?rev=1058523&r1=1058522&r2=1058523&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_wc/db-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_wc/db-test.c Thu Jan 13 11:58:52 2011
@@ -329,6 +329,7 @@ create_fake_wc(const char *subdir, int f
   const char * const my_statements[] = {
     statements[STMT_CREATE_SCHEMA],
     statements[STMT_CREATE_NODES],
+    statements[STMT_CREATE_NODES_TRIGGERS],
     TESTING_DATA,
     NULL
   };

Modified: subversion/trunk/subversion/tests/libsvn_wc/entries-compat.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_wc/entries-compat.c?rev=1058523&r1=1058522&r2=1058523&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_wc/entries-compat.c (original)
+++ subversion/trunk/subversion/tests/libsvn_wc/entries-compat.c Thu Jan 13 11:58:52 2011
@@ -336,12 +336,14 @@ create_fake_wc(const char *subdir, int f
   const char * const my_statements[] = {
     statements[STMT_CREATE_SCHEMA],
     statements[STMT_CREATE_NODES],
+    statements[STMT_CREATE_NODES_TRIGGERS],
     TESTING_DATA,
     NULL
   };
   const char * const M_statements[] = {
     statements[STMT_CREATE_SCHEMA],
     statements[STMT_CREATE_NODES],
+    statements[STMT_CREATE_NODES_TRIGGERS],
     M_TESTING_DATA,
     NULL
   };