⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fs.c

📁 subversion-1.4.3-1.tar.gz 配置svn的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* fs.c --- creating, opening and closing filesystems * * ==================================================================== * Copyright (c) 2000-2006 CollabNet.  All rights reserved. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution.  The terms * are also available at http://subversion.tigris.org/license-1.html. * If newer versions of this license are posted there, you may use a * newer version instead, at your option. * * This software consists of voluntary contributions made by many * individuals.  For exact contribution history, see the revision * history and logs, available at http://subversion.tigris.org/. * ==================================================================== */#include <stdlib.h>#include <stdio.h>#include <string.h>#define APU_WANT_DB#include <apu_want.h>#include <apr_general.h>#include <apr_pools.h>#include <apr_file_io.h>#include "svn_pools.h"#include "svn_fs.h"#include "svn_path.h"#include "svn_utf.h"#include "svn_delta.h"#include "svn_version.h"#include "fs.h"#include "err.h"#include "dag.h"#include "revs-txns.h"#include "uuid.h"#include "tree.h"#include "id.h"#include "lock.h"#include "svn_private_config.h"#include "bdb/bdb-err.h"#include "bdb/bdb_compat.h"#include "bdb/env.h"#include "bdb/nodes-table.h"#include "bdb/rev-table.h"#include "bdb/txn-table.h"#include "bdb/copies-table.h"#include "bdb/changes-table.h"#include "bdb/reps-table.h"#include "bdb/strings-table.h"#include "bdb/uuids-table.h"#include "bdb/locks-table.h"#include "bdb/lock-tokens-table.h"#include "../libsvn_fs/fs-loader.h"/* Checking for return values, and reporting errors.  *//* Check that we're using the right Berkeley DB version. *//* FIXME: This check should be abstracted into the DB back-end layer. */static svn_error_t *check_bdb_version(void){  int major, minor, patch;  db_version(&major, &minor, &patch);  /* First, check that we're using a reasonably correct of Berkeley DB. */  if ((major < SVN_FS_WANT_DB_MAJOR)      || (major == SVN_FS_WANT_DB_MAJOR && minor < SVN_FS_WANT_DB_MINOR)      || (major == SVN_FS_WANT_DB_MAJOR && minor == SVN_FS_WANT_DB_MINOR          && patch < SVN_FS_WANT_DB_PATCH))    return svn_error_createf(SVN_ERR_FS_GENERAL, 0,                             _("Bad database version: got %d.%d.%d,"                               " should be at least %d.%d.%d"),                             major, minor, patch,                             SVN_FS_WANT_DB_MAJOR,                             SVN_FS_WANT_DB_MINOR,                             SVN_FS_WANT_DB_PATCH);  /* Now, check that the version we're running against is the same as     the one we compiled with. */  if (major != DB_VERSION_MAJOR || minor != DB_VERSION_MINOR)    return svn_error_createf(SVN_ERR_FS_GENERAL, 0,                             _("Bad database version:"                               " compiled with %d.%d.%d,"                               " running against %d.%d.%d"),                             DB_VERSION_MAJOR,                             DB_VERSION_MINOR,                             DB_VERSION_PATCH,                             major, minor, patch);  return SVN_NO_ERROR;}/* If FS is already open, then return an SVN_ERR_FS_ALREADY_OPEN   error.  Otherwise, return zero.  */static svn_error_t *check_already_open(svn_fs_t *fs){  if (fs->fsap_data)    return svn_error_create(SVN_ERR_FS_ALREADY_OPEN, 0,                            _("Filesystem object already open"));  else    return SVN_NO_ERROR;}/* Cleanup functions.  *//* Close a database in the filesystem FS.   DB_PTR is a pointer to the DB pointer in *FS to close.   NAME is the name of the database, for use in error messages.  */static svn_error_t *cleanup_fs_db(svn_fs_t *fs, DB **db_ptr, const char *name){  /* If the BDB environment is panicked, don't do anything, since     attempting to close the database will fail anyway. */  base_fs_data_t *bfd = fs->fsap_data;  if (*db_ptr && !svn_fs_bdb__get_panic(bfd->bdb))    {      DB *db = *db_ptr;      char *msg = apr_psprintf(fs->pool, "closing '%s' database", name);      int db_err;      *db_ptr = 0;      db_err = db->close(db, 0);      if (db_err == DB_RUNRECOVERY)        {          /* We can ignore DB_RUNRECOVERY errors from DB->close, but             must set the panic flag in the environment baton.  The             error will be propagated appropriately from             svn_fs_bdb__close. */          svn_fs_bdb__set_panic(bfd->bdb);          db_err = 0;        }#if SVN_BDB_HAS_DB_INCOMPLETE      /* We can ignore DB_INCOMPLETE on db->close and db->sync; it       * just means someone else was using the db at the same time       * we were.  See the Berkeley documentation at:       * http://www.sleepycat.com/docs/ref/program/errorret.html#DB_INCOMPLETE       * http://www.sleepycat.com/docs/api_c/db_close.html       */      if (db_err == DB_INCOMPLETE)        db_err = 0;#endif /* SVN_BDB_HAS_DB_INCOMPLETE */      SVN_ERR(BDB_WRAP(fs, msg, db_err));    }  return SVN_NO_ERROR;}/* Close whatever Berkeley DB resources are allocated to FS.  */static svn_error_t *cleanup_fs(svn_fs_t *fs){  base_fs_data_t *bfd = fs->fsap_data;  bdb_env_baton_t *bdb = (bfd ? bfd->bdb : NULL);  if (!bdb)    return SVN_NO_ERROR;  /* Close the databases.  */  SVN_ERR(cleanup_fs_db(fs, &bfd->nodes, "nodes"));  SVN_ERR(cleanup_fs_db(fs, &bfd->revisions, "revisions"));  SVN_ERR(cleanup_fs_db(fs, &bfd->transactions, "transactions"));  SVN_ERR(cleanup_fs_db(fs, &bfd->copies, "copies"));  SVN_ERR(cleanup_fs_db(fs, &bfd->changes, "changes"));  SVN_ERR(cleanup_fs_db(fs, &bfd->representations, "representations"));  SVN_ERR(cleanup_fs_db(fs, &bfd->strings, "strings"));  SVN_ERR(cleanup_fs_db(fs, &bfd->uuids, "uuids"));  SVN_ERR(cleanup_fs_db(fs, &bfd->locks, "locks"));  SVN_ERR(cleanup_fs_db(fs, &bfd->lock_tokens, "lock-tokens"));  /* Finally, close the environment.  */  bfd->bdb = 0;  {    svn_error_t *err = svn_fs_bdb__close(bdb);    if (err)      return svn_error_createf        (err->apr_err, err,         _("Berkeley DB error for filesystem '%s'"           " while closing environment:\n"),         fs->path);  }  return SVN_NO_ERROR;}#if 0   /* Set to 1 for instrumenting. */static void print_fs_stats(svn_fs_t *fs){  base_fs_data_t *bfd = fs->fsap_data;  DB_TXN_STAT *t;  DB_LOCK_STAT *l;  int db_err;  /* Print transaction statistics for this DB env. */  if ((db_err = bfd->bdb->env->txn_stat(bfd->bdb->env, &t, 0)) != 0)    fprintf(stderr, "Error running bfd->bdb->env->txn_stat(): %s",            db_strerror(db_err));  else    {      printf("*** DB transaction stats, right before closing env:\n");      printf("   Number of transactions currently active: %d\n",             t->st_nactive);      printf("   Max number of active transactions at any one time: %d\n",             t->st_maxnactive);      printf("   Number of transactions that have begun: %d\n",             t->st_nbegins);      printf("   Number of transactions that have aborted: %d\n",             t->st_naborts);      printf("   Number of transactions that have committed: %d\n",             t->st_ncommits);      printf("   Number of times a thread was forced to wait: %d\n",             t->st_region_wait);      printf("   Number of times a thread didn't need to wait: %d\n",             t->st_region_nowait);      printf("*** End DB transaction stats.\n\n");    }  /* Print transaction statistics for this DB env. */  if ((db_err = bfd->bdb->env->lock_stat(bfd->bdb->env, &l, 0)) != 0)    fprintf(stderr, "Error running bfd->bdb->env->lock_stat(): %s",            db_strerror(db_err));  else    {      printf("*** DB lock stats, right before closing env:\n");      printf("   The number of current locks: %d\n",             l->st_nlocks);      printf("   Max number of locks at any one time: %d\n",             l->st_maxnlocks);      printf("   Number of current lockers: %d\n",             l->st_nlockers);      printf("   Max number of lockers at any one time: %d\n",             l->st_maxnlockers);      printf("   Number of current objects: %d\n",             l->st_nobjects);      printf("   Max number of objects at any one time: %d\n",             l->st_maxnobjects);      printf("   Total number of locks requested: %d\n",             l->st_nrequests);      printf("   Total number of locks released: %d\n",             l->st_nreleases);      printf("   Total number of lock reqs failed because "             "DB_LOCK_NOWAIT was set: %d\n", l->st_nnowaits);      printf("   Total number of locks not immediately available "             "due to conflicts: %d\n", l->st_nconflicts);      printf("   Number of deadlocks detected: %d\n", l->st_ndeadlocks);      printf("   Number of times a thread waited before "             "obtaining the region lock: %d\n", l->st_region_wait);      printf("   Number of times a thread didn't have to wait: %d\n",             l->st_region_nowait);      printf("*** End DB lock stats.\n\n");    }}#else#  define print_fs_stats(fs)#endif /* 0/1 *//* An APR pool cleanup function for a filesystem.  DATA must be a   pointer to the filesystem to clean up.   When the filesystem object's pool is freed, we want the resources   held by Berkeley DB to go away, just like everything else.  So we   register this cleanup function with the filesystem's pool, and let   it take care of closing the databases, the environment, and any   other DB objects we might be using.  APR calls this function before   actually freeing the pool's memory.   It's a pity that we can't return an svn_error_t object from an APR   cleanup function.  For now, we return the rather generic   SVN_ERR_FS_CLEANUP, and pass the real svn_error_t to the registered   warning callback.  */static apr_status_tcleanup_fs_apr(void *data){  svn_fs_t *fs = data;  svn_error_t *err;  print_fs_stats(fs);  err = cleanup_fs(fs);  if (! err)    return APR_SUCCESS;  /* Darn. An error during cleanup. Call the warning handler to     try and do something "right" with this error. Note that     the default will simply abort().  */  (*fs->warning)(fs->warning_baton, err);  svn_error_clear(err);  return SVN_ERR_FS_CLEANUP;}static svn_error_t *base_bdb_set_errcall(svn_fs_t *fs,                     void (*db_errcall_fcn)(const char *errpfx, char *msg)){  base_fs_data_t *bfd = fs->fsap_data;  SVN_ERR(svn_fs_base__check_fs(fs));  bfd->bdb->error_info->user_callback = db_errcall_fcn;  return SVN_NO_ERROR;}/* Write the DB_CONFIG file. */static svn_error_t *bdb_write_config  (svn_fs_t *fs){  const char *dbconfig_file_name =    svn_path_join(fs->path, BDB_CONFIG_FILE, fs->pool);  apr_file_t *dbconfig_file = NULL;  int i;  static const char dbconfig_contents[] =    "# This is the configuration file for the Berkeley DB environment\n"    "# used by your Subversion repository.\n"    "# You must run 'svnadmin recover' whenever you modify this file,\n"    "# for your changes to take effect.\n"    "\n"    "### Lock subsystem\n"    "#\n"    "# Make sure you read the documentation at:\n"    "#\n"    "#   http://www.sleepycat.com/docs/ref/lock/max.html\n"    "#\n"    "# before tweaking these values.\n"    "set_lk_max_locks   2000\n"    "set_lk_max_lockers 2000\n"    "set_lk_max_objects 2000\n"    "\n"    "### Log file subsystem\n"    "#\n"    "# Make sure you read the documentation at:\n"    "#\n"    "#   http://www.sleepycat.com/docs/api_c/env_set_lg_bsize.html\n"    "#   http://www.sleepycat.com/docs/api_c/env_set_lg_max.html\n"    "#   http://www.sleepycat.com/docs/ref/log/limits.html\n"    "#\n"    "# Increase the size of the in-memory log buffer from the default\n"    "# of 32 Kbytes to 256 Kbytes.  Decrease the log file size from\n"    "# 10 Mbytes to 1 Mbyte.  This will help reduce the amount of disk\n"    "# space required for hot backups.  The size of the log file must be\n"    "# at least four times the size of the in-memory log buffer.\n"    "#\n"    "# Note: Decreasing the in-memory buffer size below 256 Kbytes\n"    "# will hurt commit performance. For details, see this post from\n"    "# Daniel Berlin <dan@dberlin.org>:\n"    "#\n"    "# http://subversion.tigris.org/servlets/ReadMsg?list=dev&msgId=161960\n"    "set_lg_bsize     262144\n"    "set_lg_max      1048576\n"    "#\n"    "# If you see \"log region out of memory\" errors, bump lg_regionmax.\n"    "# See http://www.sleepycat.com/docs/ref/log/config.html and\n"    "# http://svn.haxx.se/users/archive-2004-10/1001.shtml for more.\n"    "set_lg_regionmax 131072\n"    "#\n"    /* ### Configure this with "svnadmin create --bdb-cache-size" */    "# The default cache size in BDB is only 256k. As explained in\n"    "# http://svn.haxx.se/dev/archive-2004-12/0369.shtml, this is too\n"    "# small for most applications. Bump this number if \"db_stat -m\"\n"    "# shows too many cache misses.\n"    "set_cachesize    0 1048576 1\n";  /* Run-time configurable options.     Each option set consists of a minimum required BDB version, a     config hash key, a header, an inactive form and an active     form. We always write the header; then, depending on the     run-time configuration and the BDB version we're compiling     against, we write either the active or inactive form of the     value. */  static const struct  {    int bdb_major;    int bdb_minor;    const char *config_key;    const char *header;    const char *inactive;    const char *active;  } dbconfig_options[] = {    /* Controlled by "svnadmin create --bdb-txn-nosync" */    { 4, 0, SVN_FS_CONFIG_BDB_TXN_NOSYNC,      /* header */      "#\n"      "# Disable fsync of log files on transaction commit. Read the\n"      "# documentation about DB_TXN_NOSYNC at:\n"      "#\n"      "#   http://www.sleepycat.com/docs/api_c/env_set_flags.html\n"      "#\n"      "# [requires Berkeley DB 4.0]\n",      /* inactive */      "# set_flags DB_TXN_NOSYNC\n",      /* active */      "set_flags DB_TXN_NOSYNC\n" },    /* Controlled by "svnadmin create --bdb-log-keep" */    { 4, 2, SVN_FS_CONFIG_BDB_LOG_AUTOREMOVE,      /* header */      "#\n"      "# Enable automatic removal of unused transaction log files.\n"      "# Read the documentation about DB_LOG_AUTOREMOVE at:\n"      "#\n"      "#   http://www.sleepycat.com/docs/api_c/env_set_flags.html\n"      "#\n"      "# [requires Berkeley DB 4.2]\n",      /* inactive */      "# set_flags DB_LOG_AUTOREMOVE\n",      /* active */      "set_flags DB_LOG_AUTOREMOVE\n" },

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -