Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

db_setlsn.c

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 2000-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: db_setlsn.c,v 12.8 2005/10/21 19:17:40 bostic Exp $
00008  */
00009 
00010 #include "db_config.h"
00011 
00012 #ifndef NO_SYSTEM_INCLUDES
00013 #include <sys/types.h>
00014 #endif
00015 
00016 #include "db_int.h"
00017 #include "dbinc/db_page.h"
00018 #include "dbinc/db_shash.h"
00019 #include "dbinc/db_am.h"
00020 #include "dbinc/mp.h"
00021 
00022 static int __env_lsn_reset __P((DB_ENV *, const char *, int));
00023 
00024 /*
00025  * __env_lsn_reset_pp --
00026  *      DB_ENV->lsn_reset pre/post processing.
00027  *
00028  * PUBLIC: int __env_lsn_reset_pp __P((DB_ENV *, const char *, u_int32_t));
00029  */
00030 int
00031 __env_lsn_reset_pp(dbenv, name, flags)
00032         DB_ENV *dbenv;
00033         const char *name;
00034         u_int32_t flags;
00035 {
00036         DB_THREAD_INFO *ip;
00037         int handle_check, ret, t_ret;
00038 
00039         PANIC_CHECK(dbenv);
00040         ENV_ILLEGAL_BEFORE_OPEN(dbenv, "DB_ENV->lsn_reset");
00041 
00042         /*
00043          * !!!
00044          * The actual argument checking is simple, do it inline, outside of
00045          * the replication block.
00046          */
00047         if (flags != 0 && flags != DB_ENCRYPT)
00048                 return (__db_ferr(dbenv, "DB_ENV->lsn_reset", 0));
00049 
00050         ENV_ENTER(dbenv, ip);
00051 
00052         /* Check for replication block. */
00053         handle_check = IS_ENV_REPLICATED(dbenv);
00054         if (handle_check && (ret = __env_rep_enter(dbenv, 1)) != 0)
00055                 goto err;
00056 
00057         ret = __env_lsn_reset(dbenv, name, LF_ISSET(DB_ENCRYPT) ? 1 : 0);
00058 
00059         if (handle_check && (t_ret = __env_db_rep_exit(dbenv)) != 0 && ret == 0)
00060                 ret = t_ret;
00061 
00062 err:    ENV_LEAVE(dbenv, ip);
00063         return (ret);
00064 }
00065 
00066 /*
00067  * __env_lsn_reset --
00068  *      Reset the LSNs for every page in the file.
00069  */
00070 static int
00071 __env_lsn_reset(dbenv, name, encrypted)
00072         DB_ENV *dbenv;
00073         const char *name;
00074         int encrypted;
00075 {
00076         DB *dbp;
00077         DB_MPOOLFILE *mpf;
00078         PAGE *pagep;
00079         db_pgno_t pgno;
00080         int t_ret, ret;
00081 
00082         /* Create the DB object. */
00083         if ((ret = db_create(&dbp, dbenv, 0)) != 0)
00084                 return (ret);
00085 
00086         /* If configured with a password, the databases are encrypted. */
00087         if (encrypted && (ret = __db_set_flags(dbp, DB_ENCRYPT)) != 0)
00088                 goto err;
00089 
00090         /*
00091          * Open the DB file.
00092          *
00093          * !!!
00094          * Note DB_RDWRMASTER flag, we need to open the master database file
00095          * for writing in this case.
00096          */
00097         if ((ret = __db_open(dbp, NULL,
00098             name, NULL, DB_UNKNOWN, DB_RDWRMASTER, 0, PGNO_BASE_MD)) != 0)
00099                 goto err;
00100 
00101         /* Reset the LSN on every page of the database file. */
00102         mpf = dbp->mpf;
00103         for (pgno = 0;
00104             (ret = __memp_fget(mpf, &pgno, 0, &pagep)) == 0; ++pgno) {
00105                 LSN_NOT_LOGGED(pagep->lsn);
00106                 if ((ret = __memp_fput(mpf, pagep, DB_MPOOL_DIRTY)) != 0)
00107                         goto err;
00108         }
00109 
00110         if (ret == DB_PAGE_NOTFOUND)
00111                 ret = 0;
00112 
00113 err:    if ((t_ret = __db_close(dbp, NULL, 0)) != 0 && ret == 0)
00114                 ret = t_ret;
00115         return (ret);
00116 }

Generated on Sun Dec 25 12:14:21 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2