[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Berkeley DB verbose error messages

From: Sander Striker <striker_at_apache.org>
Date: 2003-09-25 20:58:26 CEST

Subject says it all.

This patch is probably not the nicest thing to do, but reading the
Berkeley DB documentation it should be a safe thing to do.

The obvious 'correct' solution would be to store unique keys in a
hash, mapping keys to fs objects. The key would then be put in the
prefix and the verbose error handler would translate the key back
to the fs. Add to this lock protection and it starts to get complex
real fast. Personally I can live with the hack.

Thoughts?

Sander

Log:
* subversion/libsvn_fs/bdb/bdb-err.c

  (svn_fs__bdb_dberrf): Change API to gain access to the fs object.
    Append the verbose error message provided by Berkeley DB, if any,
    to the constructed error.

  (svn_fs__bdb_wrap_db): Update call to svn_fs__bdb_dberrf().

* subversion/libsvn_fs/bdb/bdb-err.h

  (svn_fs__bdb_dberrf): Change API to gain access to the fs object.

* subversion/libsvn_fs/fs.c

  (verbose_error_handler): New function. Store verbose error message
    Berkeley DB gives us in the fs object.

  (setup_verbose_err): New function. Set Berekely DB error callback
    function and 'prefix' (dubbing as baton) appropiately.

  (svn_fs_create_berkeley, svn_fs_open_berkeley): Add calls to
    setup_verbose_err().

* subversion/libsvn_fs/fs.h

  (svn_fs_t): Add an error message placeholder.

Index: subversion/libsvn_fs/bdb/bdb-err.c
===================================================================
--- subversion/libsvn_fs/bdb/bdb-err.c (revision 7194)
+++ subversion/libsvn_fs/bdb/bdb-err.c (working copy)
@@ -51,7 +51,7 @@

 
 svn_error_t *
-svn_fs__bdb_dberrf (int db_err, const char *fmt, ...)
+svn_fs__bdb_dberrf (svn_fs_t *fs, int db_err, const char *fmt, ...)
 {
   va_list ap;
   char *msg;
@@ -61,6 +61,12 @@
   msg = apr_pvsprintf (err->pool, fmt, ap);
   va_end (ap);
   err->message = apr_psprintf (err->pool, "%s%s", msg, db_strerror (db_err));
+ if (fs && fs->errmsg)
+ {
+ err->message = apr_pstrcat (err->pool, err->message, "\n",
+ fs->errmsg, NULL);
+ fs->errmsg = NULL;
+ }
   return err;
 }

@@ -70,7 +76,7 @@
 {
   if (! db_err)
     return SVN_NO_ERROR;
- return svn_fs__bdb_dberrf (db_err,
+ return svn_fs__bdb_dberrf (fs, db_err,
                              "Berkeley DB error while %s for filesystem %s:\n",
                              operation, fs->path ? fs->path : "(none)");
 }
Index: subversion/libsvn_fs/bdb/bdb-err.h
===================================================================
--- subversion/libsvn_fs/bdb/bdb-err.h (revision 7194)
+++ subversion/libsvn_fs/bdb/bdb-err.h (working copy)
@@ -50,7 +50,7 @@

    There is no separator between the two messages; if you want one,
    you should include it in FMT. */
-svn_error_t *svn_fs__bdb_dberrf (int db_err,
+svn_error_t *svn_fs__bdb_dberrf (svn_fs_t *fs, int db_err,
                                  const char *fmt, ...);

Index: subversion/libsvn_fs/fs.c
===================================================================
--- subversion/libsvn_fs/fs.c (revision 7194)
+++ subversion/libsvn_fs/fs.c (working copy)
@@ -360,7 +360,31 @@
 }

+/* Note that we 'abuse' the error prefix as a userdata field.
+ The documentation suggests that this is safe:
+
+ http://www.sleepycat.com/docs/api_c/env_set_errpfx.html
+ */
+
+static
+void
+verbose_error_handler (const char *errpfx, char *msg)
+{
+ svn_fs_t *fs = (void *)errpfx;
+ fs->errmsg = msg;
+}
+
+static
 svn_error_t *
+setup_verbose_err (svn_fs_t *fs)
+{
+ fs->env->set_errcall (fs->env, verbose_error_handler);
+ fs->env->set_errpfx (fs->env, (void *)fs);
+
+ return SVN_NO_ERROR;
+}
+
+svn_error_t *
 svn_fs_create_berkeley (svn_fs_t *fs, const char *path)
 {
   apr_status_t apr_err;
@@ -483,6 +507,8 @@
                                     0666));
   if (svn_err) goto error;

+ SVN_ERR (setup_verbose_err (fs));
+
   /* Create the databases in the environment. */
   svn_err = BDB_WRAP (fs, "creating 'nodes' table",
                      svn_fs__bdb_open_nodes_table (&fs->nodes, fs->env, 1));
@@ -558,6 +584,8 @@
                                     0666));
   if (svn_err) goto error;

+ SVN_ERR (setup_verbose_err (fs));
+
   /* Open the various databases. */
   svn_err = BDB_WRAP (fs, "opening 'nodes' table",
                      svn_fs__bdb_open_nodes_table (&fs->nodes, fs->env, 0));
Index: subversion/libsvn_fs/fs.h
===================================================================
--- subversion/libsvn_fs/fs.h (revision 7194)
+++ subversion/libsvn_fs/fs.h (working copy)
@@ -45,6 +45,9 @@
      This establishes the scope of the filesystem's transactions. */
   DB_ENV *env;

+ /* A placeholder for verbose Berkeley DB error messages */
+ const char *errmsg;
+
   /* The filesystem's various tables. See `structure' for details. */
   DB *changes;
   DB *copies;

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Thu Sep 25 21:43:41 2003

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.