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

Re: Enhancing and possibly renaming svnadmin archive command

From: Vladimir Berezniker <vmpn_at_tigris.org>
Date: 2003-08-06 18:31:26 CEST

I hope this patch is somewhere in the middle of different views of how db log
files listing should be handled.

Log Message:

* include/svn_fs.h
         (svn_fs_berkeley_logfiles): Renamed from svn_fs_berkeley_archive to be
more in line with actual purpose of the function. Change return pointer to
apr_array_header_t type from pointer to NULL-terminated array of const char *.
Add parameter specifying whether to return all or only unused log file names.

* libsvn_fs/fs.c
         (svn_fs_berkeley_logfiles): Implement the function as specified in
include/svn_fs.h.

* include/svn_repos.h
         (svn_repos_db_logfiles): Created wrapper function around
svn_fs_berkeley_logfiles to return log paths relative to the repository root.

* libsvn_repos/repos.c
       (svn_repos_db_logfiles): Implement the function as specified in
include/svn_repos.h.

* svnadmin/main.c
        Rename "archive" sub command to "lsdblogs" and change default behavior from
listing only unused logs to listing all log files, to be consistent with the
name of sub command. Added --only-unused option to mimic the behavior of
replaced "archive" sub command.

Patch:
Index: subversion/svnadmin/main.c
===================================================================
--- subversion/svnadmin/main.c (revision 6656)
+++ subversion/svnadmin/main.c (working copy)
@@ -55,7 +55,6 @@
  /** Subcommands. **/

  static svn_opt_subcommand_t
- subcommand_archive,
    subcommand_create,
    subcommand_createtxn,
    subcommand_dump,
@@ -63,6 +62,7 @@
    subcommand_load,
    subcommand_lscr,
    subcommand_lstxns,
+ subcommand_lsdblogs,
    subcommand_recover,
    subcommand_rmtxns,
    subcommand_setlog;
@@ -77,7 +77,8 @@
      svnadmin__ignore_uuid,
      svnadmin__force_uuid,
      svnadmin__parent_dir,
- svnadmin__bdb_txn_nosync
+ svnadmin__bdb_txn_nosync,
+ svnadmin__only_unused
    };

  /* Option codes and descriptions.
@@ -128,6 +129,9 @@
      {SVN_FS_CONFIG_BDB_TXN_NOSYNC, svnadmin__bdb_txn_nosync, 0,
       "disable fsync at database transaction commit [Berkeley DB]."},

+ {"only-unused", svnadmin__only_unused, 0,
+ "list only used log files, that can be archived."},
+
      {NULL}
    };

@@ -137,11 +141,6 @@
   */
  static const svn_opt_subcommand_desc_t cmd_table[] =
    {
- {"archive", subcommand_archive, {0},
- "usage: svnadmin archive REPOS_PATH\n\n"
- "Ask Berkeley DB which logfiles can be safely deleted.\n\n",
- {0} },
-
      {"create", subcommand_create, {0},
       "usage: svnadmin create REPOS_PATH\n\n"
       "Create a new, empty repository at REPOS_PATH.\n",
@@ -186,6 +185,12 @@
       "repository.)\n",
       {svnadmin__follow_copies} },

+ {"lsdblogs", subcommand_lsdblogs, {0},
+ "usage: svnadmin lsdblogs REPOS_PATH\n\n"
+ "List all Berkeley DB log files.\n\n",
+ {svnadmin__only_unused} },
+
+
      {"lstxns", subcommand_lstxns, {0},
       "usage: svnadmin lstxns REPOS_PATH\n\n"
       "Print the names of all uncommitted transactions.\n",
@@ -227,6 +232,7 @@
    svn_boolean_t follow_copies; /* --copies */
    svn_boolean_t quiet; /* --quiet */
    svn_boolean_t bdb_txn_nosync; /* --bdb-txn-nosync */
+ svn_boolean_t only_unused; /* --only-unused */
    enum svn_repos_load_uuid uuid_action; /* --ignore-uuid,
                                                         --force-uuid */
    const char *on_disk;
@@ -490,23 +496,27 @@

  /* This implements `svn_opt_subcommand_t'. */
  svn_error_t *
-subcommand_archive (apr_getopt_t *os, void *baton, apr_pool_t *pool)
+subcommand_lsdblogs (apr_getopt_t *os, void *baton, apr_pool_t *pool)
  {
- svn_repos_t *repos;
    struct svnadmin_opt_state *opt_state = baton;
- char **logfiles;
- char **filename;
+ apr_array_header_t *logfiles;
+ int log;

- SVN_ERR (svn_repos_open (&repos, opt_state->repository_path, pool));
+ SVN_ERR (svn_repos_db_logfiles (&logfiles,
+ opt_state->repository_path,
+ opt_state->only_unused,
+ pool));

- SVN_ERR (svn_fs_berkeley_archive (&logfiles,
- svn_repos_db_env (repos, pool), pool));
-
    if (logfiles == NULL)
- return SVN_NO_ERROR;
+ {
+ return SVN_NO_ERROR;
+ }

- for (filename = logfiles; *filename != NULL; ++filename)
- printf ("%s\n", *filename);
+ /* Loop, printing log files. */
+ for (log = 0; log < logfiles->nelts; log++)
+ {
+ printf ("%s\n", APR_ARRAY_IDX (logfiles, log, const char *));
+ }

    return SVN_NO_ERROR;
  }
@@ -750,6 +760,9 @@
        case svnadmin__bdb_txn_nosync:
          opt_state.bdb_txn_nosync = TRUE;
          break;
+ case svnadmin__only_unused:
+ opt_state.only_unused = TRUE;
+ break;
        default:
          {
            subcommand_help (NULL, NULL, pool);
Index: subversion/include/svn_fs.h
===================================================================
--- subversion/include/svn_fs.h (revision 6656)
+++ subversion/include/svn_fs.h (working copy)
@@ -193,19 +193,22 @@
                                        apr_pool_t *pool);

-/** Return a NULL-terminated array of absolute paths to @a logfiles
- * that are no longer is use by the DB-based Subversion filesystem,
- * stored in the environment @a path. Do any necessary allocation
- * within @a pool.
+/** Set @a *logfiles to array of <tt>const char *</tt> log file names
+ * of Berkeley DB-based Subversion filesystem.
   *
- * This function wraps the same Berkeley DB 'log_archive' function
+ * @a only_unused specifies whether to include used log file names in the list:
+ * TRUE - Only unused logs are included
+ * FALSE - All logs are included
+ *
+ * This function wraps the Berkeley DB 'log_archive' function
   * called by the db_archive binary. Repository administrators may
   * want to run this function periodically and delete the unused log
   * files, as a way of reclaiming disk space.
   */
-svn_error_t *svn_fs_berkeley_archive (char ***logfiles,
- const char *path,
- apr_pool_t *pool);
+svn_error_t *svn_fs_berkeley_logfiles (apr_array_header_t **logfiles,
+ const char *path,
+ svn_boolean_t only_unused,
+ apr_pool_t *pool);

  /** @} */
Index: subversion/include/svn_repos.h
===================================================================
--- subversion/include/svn_repos.h (revision 6656)
+++ subversion/include/svn_repos.h (working copy)
@@ -108,6 +108,17 @@
  svn_error_t *svn_repos_recover (const char *path, apr_pool_t *pool);

+/** This function is a wrapper around svn_fs_berkeley_logfiles(),
+ * returning log file paths relative to the root of the repository.
+ *
+ * @copydoc svn_fs_berkeley_logfiles()
+ */
+svn_error_t *svn_repos_db_logfiles (apr_array_header_t **logfiles,
+ const char *path,
+ svn_boolean_t only_unused,
+ apr_pool_t *pool);
+
+
  
  /* Repository Paths */

Index: subversion/libsvn_fs/fs.c
===================================================================
--- subversion/libsvn_fs/fs.c (revision 6656)
+++ subversion/libsvn_fs/fs.c (working copy)
@@ -651,16 +651,19 @@
  /* Running the 'archive' command on a Berkeley DB-based filesystem. */

-svn_error_t *
-svn_fs_berkeley_archive (char ***logfiles,
- const char *path,
- apr_pool_t *pool)
+svn_error_t *svn_fs_berkeley_logfiles (apr_array_header_t **logfiles,
+ const char *path,
+ svn_boolean_t only_unused,
+ apr_pool_t *pool)
  {
    int db_err;
    DB_ENV *env;
    const char *path_native;
    char **filelist;
+ char **filename;

+ *logfiles = NULL;
+
    db_err = db_env_create (&env, 0);
    if (db_err)
      return svn_fs__bdb_dberr (db_err);
@@ -673,16 +676,46 @@
    if (db_err)
      return svn_fs__bdb_dberr (db_err);

- db_err = env->log_archive (env, &filelist,
- DB_ARCH_ABS /* return absolute paths */);
+ {
+ u_int32_t flags = 0;
+
+ if(only_unused == FALSE)
+ {
+ flags |= DB_ARCH_LOG;
+ }
+
+ db_err = env->log_archive (env, &filelist, flags);
+ }
+
    if (db_err)
      return svn_fs__bdb_dberr (db_err);

+ if (filelist == NULL)
+ {
+ db_err = env->close (env, 0);
+ if (db_err)
+ return svn_fs__bdb_dberr (db_err);
+
+ return SVN_NO_ERROR;
+ }
+
+ {
+ *logfiles = apr_array_make (pool, 1, sizeof (const char *));
+
+ for (filename = filelist; *filename != NULL; ++filename)
+ {
+ APR_ARRAY_PUSH (*logfiles, const char *) = (apr_pstrdup(pool, *filename));
+ }
+
+ /* allocate_env sets malloc and free as the memory management functions,
+ therefore we use free to release memory allocated by DB_ENV */
+ free(filelist);
+ }
+
    db_err = env->close (env, 0);
    if (db_err)
      return svn_fs__bdb_dberr (db_err);

- *logfiles = filelist;
    return SVN_NO_ERROR;
  }

Index: subversion/libsvn_repos/repos.c
===================================================================
--- subversion/libsvn_repos/repos.c (revision 6656)
+++ subversion/libsvn_repos/repos.c (working copy)
@@ -1261,3 +1261,36 @@

    return SVN_NO_ERROR;
  }
+
+svn_error_t *svn_repos_db_logfiles (apr_array_header_t **logfiles,
+ const char *path,
+ svn_boolean_t only_unused,
+ apr_pool_t *pool)
+{
+ svn_repos_t *repos;
+ int log;
+
+ SVN_ERR (get_repos (&repos, path,
+ APR_FLOCK_SHARED,
+ FALSE, /* Do not open fs. */
+ pool));
+
+ SVN_ERR (svn_fs_berkeley_logfiles (logfiles,
+ svn_repos_db_env (repos, pool),
+ only_unused,
+ pool));
+
+ if (logfiles == NULL)
+ {
+ return SVN_NO_ERROR;
+ }
+
+ /* Loop, printing log files. */
+ for (log = 0; log < (*logfiles)->nelts; log++)
+ {
+ const char ** log_file = &(APR_ARRAY_IDX (*logfiles, log, const char *));
+ *log_file = svn_path_join(SVN_REPOS__DB_DIR, *log_file, pool);
+ }
+
+ return SVN_NO_ERROR;
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Aug 6 18:32:03 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.