db

db_int.h

Go to the documentation of this file.
00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1996, 1997, 1998, 1999, 2000
00005  * Sleepycat Software. All rights reserved.
00006  *
00007  * $Id: db__int_8h-source.html,v 1.1 2008年06月08日 10:17:43 sebdiaz Exp $
00008  */
00009 
00010 #ifndef _DB_INTERNAL_H_
00011 #define _DB_INTERNAL_H_
00012 
00013 /*******************************************************
00014  * General includes.
00015  *******************************************************/
00016 #include "db.h"
00017 
00018 #ifndef NO_SYSTEM_INCLUDES
00019 #if defined(__STDC__) || defined(__cplusplus)
00020 #include <stdarg.h>
00021 #else
00022 #include <varargs.h>
00023 #endif
00024 #endif
00025 
00026 /*
00027  * XXX
00028  * We need to #undef the following LIST_XXX macros because VxWorks copied
00029  * some of them into UnixLib.h -- not all of them though, so we can't use
00030  * their versions.
00031  */
00032 #undef LIST_INIT
00033 #undef LIST_INSERT_HEAD
00034 #undef LIST_REMOVE
00035 #include "queue.h"
00036 #include "shqueue.h"
00037 
00038 #if defined(__cplusplus)
00039 extern "C" {
00040 #endif
00041 
00042 /*******************************************************
00043  * General purpose constants and macros.
00044  *******************************************************/
00045 #define UINT16_T_MAX 0xffff /* Maximum 16 bit unsigned. */
00046 #define UINT32_T_MAX 0xffffffff /* Maximum 32 bit unsigned. */
00047 
00048 #define MEGABYTE 1048576
00049 #define GIGABYTE 1073741824
00050 
00051 #define MS_PER_SEC 1000 /* Milliseconds in a second. */
00052 #define USEC_PER_MS 1000 /* Microseconds in a millisecond. */
00053 
00054 #define DB_MIN_PGSIZE 0x000200 /* Minimum page size (512). */
00055 #define DB_MAX_PGSIZE 0x010000 /* Maximum page size (65536). */
00056 
00057 #define RECNO_OOB 0 /* Illegal record number. */
00058 
00059 /*
00060  * If we are unable to determine the underlying filesystem block size, use
00061  * 8K on the grounds that most OS's use less than 8K for a VM page size.
00062  */
00063 #define DB_DEF_IOSIZE (8 * 1024)
00064 
00065 /*
00066  * Aligning items to particular sizes or in pages or memory.
00067  *
00068  * db_align_t --
00069  * Largest integral type, used to align structures in memory. We don't store
00070  * floating point types in structures, so integral types should be sufficient
00071  * (and we don't have to worry about systems that store floats in other than
00072  * power-of-2 numbers of bytes). Additionally this fixes compiler that rewrite
00073  * structure assignments and ANSI C memcpy calls to be in-line instructions
00074  * that happen to require alignment. Note: this alignment isn't sufficient for
00075  * mutexes, which depend on things like cache line alignment. Mutex alignment
00076  * is handled separately, in mutex.h.
00077  *
00078  * db_alignp_t --
00079  * Integral type that's the same size as a pointer. There are places where
00080  * DB modifies pointers by discarding the bottom bits to guarantee alignment.
00081  * We can't use db_align_t, it may be larger than the pointer, and compilers
00082  * get upset about that. So far we haven't run on any machine where there
00083  * isn't an integral type the same size as a pointer -- here's hoping.
00084  */
00085 typedef unsigned long long db_align_t;
00086 typedef unsigned long db_alignp_t;
00087 
00088 /* Align an integer to a specific boundary. */
00089 #undef ALIGN
00090 #define ALIGN(value, bound) \
00091  (((value) + (bound) - 1) & ~(((u_int)bound) - 1))
00092 
00093 /* Align a pointer to a specific boundary. */
00094 #undef ALIGNP
00095 #define ALIGNP(value, bound) ALIGN((db_alignp_t)value, bound)
00096 
00097 /*
00098  * There are several on-page structures that are declared to have a number of
00099  * fields followed by a variable length array of items. The structure size
00100  * without including the variable length array or the address of the first of
00101  * those elements can be found using SSZ.
00102  *
00103  * This macro can also be used to find the offset of a structure element in a
00104  * structure. This is used in various places to copy structure elements from
00105  * unaligned memory references, e.g., pointers into a packed page.
00106  *
00107  * There are two versions because compilers object if you take the address of
00108  * an array.
00109  */
00110 #undef SSZ
00111 #define SSZ(name, field) ((int)&(((name *)0)->field))
00112 
00113 #undef SSZA
00114 #define SSZA(name, field) ((int)&(((name *)0)->field[0]))
00115 
00116 /*
00117  * Print an address as a u_long (a u_long is the largest type we can print
00118  * portably). Most 64-bit systems have made longs 64-bits, so this should
00119  * work.
00120  */
00121 #define P_TO_ULONG(p) ((u_long)(db_alignp_t)(p))
00122 
00123 /* Structure used to print flag values. */
00124 typedef struct __fn {
00125 u_int32_t mask; /* Flag value. */
00126 const char *name; /* Flag name. */
00127 } FN;
00128 
00129 /* Set, clear and test flags. */
00130 #define FLD_CLR(fld, f) (fld) &= ~(f)
00131 #define FLD_ISSET(fld, f) ((fld) & (f))
00132 #define FLD_SET(fld, f) (fld) |= (f)
00133 #define F_CLR(p, f) (p)->flags &= ~(f)
00134 #define F_ISSET(p, f) ((p)->flags & (f))
00135 #define F_SET(p, f) (p)->flags |= (f)
00136 #define LF_CLR(f) (flags &= ~(f))
00137 #define LF_ISSET(f) (flags & (f))
00138 #define LF_SET(f) (flags |= (f))
00139 
00140 /* Display separator string. */
00141 #undef DB_LINE
00142 #define DB_LINE "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
00143 
00144 /* Unused, or not-used-yet variable. "Shut that bloody compiler up!" */
00145 #define COMPQUIET(n, v) (n) = (v)
00146 
00147 /*******************************************************
00148  * Files.
00149  *******************************************************/
00150 /*
00151  * We use 1024 as the maximum path length. It's too hard to figure out what
00152  * the real path length is, as it was traditionally stored in <sys/param.h>,
00153  * and that file isn't always available.
00154  */
00155 #undef MAXPATHLEN
00156 #define MAXPATHLEN 1024
00157 
00158 #define PATH_DOT "." /* Current working directory. */
00159 #define PATH_SEPARATOR "/" /* Path separator character. */
00160 
00161 /*
00162  * Flags understood by CDB___os_open.
00163  */
00164 #define DB_OSO_CREATE 0x001 /* POSIX: O_CREAT */
00165 #define DB_OSO_EXCL 0x002 /* POSIX: O_EXCL */
00166 #define DB_OSO_LOG 0x004 /* Opening a log file. */
00167 #define DB_OSO_RDONLY 0x008 /* POSIX: O_RDONLY */
00168 #define DB_OSO_SEQ 0x010 /* Expected sequential access. */
00169 #define DB_OSO_TEMP 0x020 /* Remove after last close. */
00170 #define DB_OSO_TRUNC 0x040 /* POSIX: O_TRUNC */
00171 
00172 /*
00173  * Seek options understood by CDB___os_seek.
00174  */
00175 typedef enum {
00176 DB_OS_SEEK_CUR, /* POSIX: SEEK_CUR */
00177 DB_OS_SEEK_END, /* POSIX: SEEK_END */
00178 DB_OS_SEEK_SET /* POSIX: SEEK_SET */
00179 } DB_OS_SEEK;
00180 
00181 /*******************************************************
00182  * Environment.
00183  *******************************************************/
00184 /* Type passed to CDB___db_appname(). */
00185 typedef enum {
00186 DB_APP_NONE=0, /* No type (region). */
00187 DB_APP_DATA, /* Data file. */
00188 DB_APP_LOG, /* Log file. */
00189 DB_APP_TMP /* Temporary file. */
00190 } APPNAME;
00191 
00192 /*
00193  * LOCKING CDB product locking.
00194  * LOCKING_ON Locking has been configured.
00195  * LOGGING_ON Logging has been configured.
00196  * MPOOL_ON Memory pool has been configured.
00197  * TXN_ON Transactions have been configured.
00198  */
00199 #define LOCKING(dbenv) F_ISSET(dbenv, DB_ENV_CDB)
00200 #define LOCKING_ON(dbenv) ((dbenv)->lk_handle != NULL)
00201 #define LOGGING_ON(dbenv) ((dbenv)->lg_handle != NULL)
00202 #define MPOOL_ON(dbenv) ((dbenv)->mp_handle != NULL)
00203 #define TXN_ON(dbenv) ((dbenv)->tx_handle != NULL)
00204 
00205 /*
00206  * STD_LOCKING Standard locking, that is, locking was configured and CDB
00207  * was not. We do not do locking in off-page duplicate trees,
00208  * so we check for that in the cursor first.
00209  */
00210 #define STD_LOCKING(dbc) \
00211  (!F_ISSET(dbc, DBC_OPD) && \
00212  !LOCKING((dbc)->dbp->dbenv) && LOCKING_ON((dbc)->dbp->dbenv))
00213 
00214 /*
00215  * IS_RECOVERING The system is running recovery.
00216  */
00217 #define IS_RECOVERING(dbenv) \
00218  (LOGGING_ON(dbenv) && \
00219  F_ISSET((DB_LOG *)(dbenv)->lg_handle, DBLOG_RECOVER))
00220 
00221 /* Most initialization methods cannot be called after open is called. */
00222 #define ENV_ILLEGAL_AFTER_OPEN(dbenv, name) \
00223  if (F_ISSET((dbenv), DB_ENV_OPEN_CALLED)) \
00224  return (CDB___db_mi_open(dbenv, name, 1));
00225 
00226 /* We're not actually user hostile, honest. */
00227 #define ENV_REQUIRES_CONFIG(dbenv, handle, subsystem) \
00228  if (handle == NULL) \
00229  return (CDB___db_env_config(dbenv, subsystem));
00230 
00231 /*******************************************************
00232  * Database Access Methods.
00233  *******************************************************/
00234 /*
00235  * DB_IS_THREADED --
00236  * The database handle is free-threaded (was opened with DB_THREAD).
00237  */
00238 #define DB_IS_THREADED(dbp) \
00239  ((dbp)->mutexp != NULL)
00240 
00241 /* Initialization methods are often illegal before/after open is called. */
00242 #define DB_ILLEGAL_AFTER_OPEN(dbp, name) \
00243  if (F_ISSET((dbp), DB_OPEN_CALLED)) \
00244  return (CDB___db_mi_open(dbp->dbenv, name, 1));
00245 #define DB_ILLEGAL_BEFORE_OPEN(dbp, name) \
00246  if (!F_ISSET((dbp), DB_OPEN_CALLED)) \
00247  return (CDB___db_mi_open(dbp->dbenv, name, 0));
00248 /* Some initialization methods are illegal if environment isn't local. */
00249 #define DB_ILLEGAL_IN_ENV(dbp, name) \
00250  if (!F_ISSET(dbp->dbenv, DB_ENV_DBLOCAL)) \
00251  return (CDB___db_mi_env(dbp->dbenv, name));
00252 #define DB_ILLEGAL_METHOD(dbp, flags) { \
00253  int __ret; \
00254  if ((__ret = CDB___dbh_am_chk(dbp, flags)) != 0) \
00255  return (__ret); \
00256 }
00257 
00258 /*
00259  * Common DBC->internal fields. Each access method adds additional fields
00260  * to this list, but the initial fields are common.
00261  */
00262 #define __DBC_INTERNAL \
00263  DBC *opd; /* Off-page duplicate cursor. */\
00264 \
00265 void *page; /* Referenced page. */ \
00266 db_pgno_t root; /* Tree root. */ \
00267 db_pgno_t pgno; /* Referenced page number. */ \
00268 db_indx_t indx; /* Referenced key item index. */\
00269 \
00270 DB_LOCK lock; /* Cursor lock. */ \
00271 db_lockmode_t lock_mode; /* Lock mode. */
00272 
00273 struct __dbc_internal {
00274 __DBC_INTERNAL
00275 };
00276 
00277 /*******************************************************
00278  * Mpool.
00279  *******************************************************/
00280 /*
00281  * File types for DB access methods. Negative numbers are reserved to DB.
00282  */
00283 #define DB_FTYPE_SET -1 /* Call pgin/pgout functions. */
00284 #define DB_FTYPE_NOTSET 0 /* Don't call... */
00285 
00286 /* Structure used as the DB pgin/pgout pgcookie. */
00287 typedef struct __dbpginfo {
00288 size_t db_pagesize; /* Underlying page size. */
00289 int needswap; /* If swapping required. */
00290 } DB_PGINFO;
00291 
00292 /*******************************************************
00293  * Log.
00294  *******************************************************/
00295 /* Initialize an LSN to 'zero'. */
00296 #define ZERO_LSN(LSN) do { \
00297  (LSN).file = 0; \
00298  (LSN).offset = 0; \
00299 } while (0)
00300 
00301 /* Return 1 if LSN is a 'zero' lsn, otherwise return 0. */
00302 #define IS_ZERO_LSN(LSN) ((LSN).file == 0)
00303 
00304 /* Test if we need to log a change. */
00305 #define DB_LOGGING(dbc) \
00306  (LOGGING_ON((dbc)->dbp->dbenv) && !F_ISSET(dbc, DBC_RECOVER))
00307 
00308 /* Internal flag for use with internal __log_unregister. */
00309 #define DB_LOGONLY 0x01
00310 /*******************************************************
00311  * Txn.
00312  *******************************************************/
00313 #define DB_NONBLOCK(C) ((C)->txn != NULL && F_ISSET((C)->txn, TXN_NOWAIT))
00314 
00315 /*******************************************************
00316  * Global variables.
00317  *******************************************************/
00318 #ifdef HAVE_VXWORKS
00319 #include "semLib.h"
00320 #endif
00321 
00322 /*
00323  * DB global variables. Done in a single structure to minimize the name-space
00324  * pollution.
00325  */
00326 typedef struct __db_globals {
00327 u_int32_t db_mutexlocks; /* db_set_mutexlocks */
00328 u_int32_t db_pageyield; /* db_set_pageyield */
00329 u_int32_t db_panic; /* db_set_panic */
00330 u_int32_t db_region_init; /* db_set_region_init */
00331 u_int32_t db_tas_spins; /* db_set_tas_spins */
00332 #ifdef HAVE_VXWORKS
00333 u_int32_t db_global_init; /* VxWorks: inited */
00334 SEM_ID db_global_lock; /* VxWorks: global semaphore */
00335 #endif
00336 /* XA: list of opened environments. */
00337 TAILQ_HEAD(__db_envq, __db_env) db_envq;
00338 } DB_GLOBALS;
00339 
00340 #ifdef DB_INITIALIZE_DB_GLOBALS
00341 DB_GLOBALS CDB___db_global_values = {
00342 1, /* db_set_mutexlocks */
00343 0, /* db_set_pageyield */
00344 1, /* db_set_panic */
00345 0, /* db_set_region_init */
00346 0, /* db_set_tas_spins */
00347 #ifdef HAVE_VXWORKS
00348 0, /* db_global_init */
00349 NULL, /* db_global_lock */
00350 #endif
00351 /* XA environment queue */
00352 {NULL, &CDB___db_global_values.db_envq.tqh_first}
00353 };
00354 #else
00355 extern DB_GLOBALS CDB___db_global_values;
00356 #endif
00357 #define DB_GLOBAL(v) CDB___db_global_values.v
00358 
00359 /* Forward structure declarations. */
00360 struct __db_reginfo_t; typedef struct __db_reginfo_t REGINFO;
00361 struct __mutex_t; typedef struct __mutex_t MUTEX;
00362 struct __vrfy_childinfo; typedef struct __vrfy_childinfo VRFY_CHILDINFO;
00363 struct __vrfy_dbinfo; typedef struct __vrfy_dbinfo VRFY_DBINFO;
00364 struct __vrfy_pageinfo; typedef struct __vrfy_pageinfo VRFY_PAGEINFO;
00365 
00366 #if defined(__cplusplus)
00367 }
00368 #endif
00369 
00370 /*******************************************************
00371  * More general includes.
00372  *******************************************************/
00373 #include "debug.h"
00374 #include "mutex.h"
00375 #include "mutex_ext.h"
00376 #include "region.h"
00377 #include "env_ext.h"
00378 #include "os.h"
00379 #include "os_ext.h"
00380 #include "common_ext.h"
00381 
00382 #endif /* !_DB_INTERNAL_H_ */

Generated on Sun Jun 8 10:56:36 2008 for GNUmifluz by doxygen 1.5.5

AltStyle によって変換されたページ (->オリジナル) /